Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • stCky: I mean still drive a Nissan
      Today at 08:46:24 PM
    • stCky: i downloaded moparscape but still drive a Ford, when will my balls grow?
      Today at 08:46:20 PM
    • Striker Fox2: download it
      Today at 03:26:06 AM
    • Zezuma09: how do i get this game started ?
      October 22, 2017, 03:24:27 AM
    • Striker Fox2: Much more on General Board
      October 21, 2017, 04:30:25 AM
    • Striker Fox2: New price guide link [link]
      October 21, 2017, 04:30:18 AM
    • Striker Fox2: New discord link [link]
      October 21, 2017, 04:30:03 AM
    • Saltyspade10: If you are new and reading this, stick around becaus it's a great server and community! Hope to see you in-game :)
      October 21, 2017, 02:44:16 AM
    • damian6: hello i wanne buy this server can u add me
      October 20, 2017, 03:54:38 PM
    • Wilkooo: lol jks
      October 20, 2017, 02:39:53 PM
    • Wilkooo: ilyall
      October 20, 2017, 02:39:48 PM
    • tm4dz: why cant i see any download links??
      October 20, 2017, 10:46:55 AM
    • stCky: u dont need to its fudgeing sick
      October 19, 2017, 08:13:13 PM
    • odin stormborn: how do i change my username
      October 19, 2017, 12:16:51 PM
    • qazplm102938: everyone play manicps its best server out there loads to do its badboyyyy - manicps manicps shout out kiteshield
      October 19, 2017, 10:28:21 AM
    • qazplm102938: everyone play manicps its best server out there loads to do its badboyyyy - manicps manicps
      October 19, 2017, 10:11:08 AM
    • Travas: wtf
      October 19, 2017, 07:37:52 AM
    • stCky: Adaro, you are a threat to the communities image, yes
      October 18, 2017, 02:53:43 PM
    • Krackkid: Hello everyone it is I, Krackkid.
      October 18, 2017, 07:21:56 AM
    • soma_: Does anyone have an updated link to a blank Source / Client? 317/508
      October 18, 2017, 04:57:44 AM

    Author Topic: Staff Clan Chat // Regular players cannot join.  (Read 666 times)

    0 Members and 1 Guest are viewing this topic.

    OfflineSoulxs

    • Member
    • ***
    • Posts: 131
    • Thanks: +0/-0
      • View Profile
    Staff Clan Chat // Regular players cannot join.
    « on: November 14, 2015, 02:11:33 PM »
    Hey,

    So what i'm trying to do is make a clan chat for staff only. I'm having trouble with static though..
    What i'm trying is this:
    Code in ClanChatManager:
    Code: [Select]
    if(channel.equalsIgnoreCase("Staff") && Player.getRights() != PlayerRights.isStaff()){
    return;
    }

    This code is in the join chat method.

    The method for getRights():
    Code: [Select]
    public PlayerRights getRights() {
    return rights;
    }

    The method for isStaff():
    Code: [Select]
    public boolean isStaff() {
    return STAFF.contains(this);
    }
    Where STAFF is declared as:
    Code: [Select]
    private static final ImmutableSet<PlayerRights> STAFF = Sets.immutableEnumSet(SUPPORT, MODERATOR, ADMINISTRATOR, HEAD_ADMINISTRATOR, OWNER, DEVELOPER);

    How do i fix the errors? I get these:
    Code: [Select]
    src\com\ruseps\world\content\clan\ClanChatManager.java:171: error: non-static method getRights() cannot be referenced from a static context
                    if(channel.equalsIgnoreCase("Staff") && Player.getRights() != PlayerRights.isStaff()){
                                                                  ^
    src\com\ruseps\world\content\clan\ClanChatManager.java:171: error: non-static method isStaff() cannot be referenced from a static context
                    if(channel.equalsIgnoreCase("Staff") && Player.getRights() != PlayerRights.isStaff()){
                                                                                              ^
    src\com\ruseps\world\content\clan\ClanChatManager.java:171: error: incomparable types: PlayerRights and boolean
                    if(channel.equalsIgnoreCase("Staff") && Player.getRights() != PlayerRights.isStaff()){
                                                                               ^
    3 errors

    What i'm trying to do is compare the isStaff method with the player rights. How else should i do this?

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #1 on: November 15, 2015, 12:48:55 AM »
    Code: Text
    1. src\com\ruseps\world\content\clan\ClanChatManager.java:171: error: non-static method getRights() cannot be referenced from a static context
    2.                 if(channel.equalsIgnoreCase("Staff") && Player.getRights() != PlayerRights.isStaff()){
    3.                                                               ^
    This method:
    Code: Java
    1. public PlayerRights getRights(){
    2.                 return rights;
    3.         }
    Is not static.
    You are accessing it from a static context (ClassName.MethodName is static access).
    Fix 1) Make the method static static:
    To make it static, you need to add the static modifier:
    Code: Java
    1. publicstatic PlayerRights getRights(){
    2.                 return rights;
    3.         }
    Note: if the variable "rights" is not static, you will get another error.. The fix is the exact same.

    Fix 2) Access the method in a non-static context.
    I assume getRights() is defined in the Player class, or a similar one. Use your player object (I'm not sure what you use for it) to access the method "getRights()".
    Here's an example if your Player object is "c":
    Code: Java
    1. Player c;// This is the player object, ignore this...
    2. if(channel.equalsIgnoreCase("Staff")&& c.getRights()!= PlayerRights.isStaff()){
    3.  
    4. }

    Code: Text
    1. src\com\ruseps\world\content\clan\ClanChatManager.java:171: error: non-static method isStaff() cannot be referenced from a static context
    2.                 if(channel.equalsIgnoreCase("Staff") && Player.getRights() != PlayerRights.isStaff()){
    3.                                                                                           ^
    Same as above. The method isStaff() is not static, but here you access it in a static way.

    However, in this case, you should access "isStaff()" through "getRights()". The reason for this is because "isStaff()" is a method in the PlayerRights class, and your "getRights()" method returns a PlayerRights object. The object returned is not static, therefore you're not accessing it in a static context.

    Code: Text
    1. src\com\ruseps\world\content\clan\ClanChatManager.java:171: error: incomparable types: PlayerRights and boolean
    2.                 if(channel.equalsIgnoreCase("Staff") && Player.getRights() != PlayerRights.isStaff()){
    3.                                                                            ^
    Above you'd notice I said the method "getRights()" returns a PlayerRights object. The "isStaff()" method returns a boolean. Much like the error states, you cannot compare a PlayerRights object against a primitive datatype like a boolean.

    Another thing I said above, is that you should access "isStaff()" through the "getRights()" method. Due to "isStaff()" returning a boolean, we can check that boolean's state in the if statement, instead of comparing it against something else.

    Assuming your Player object is defined as "c" and the "getRights()" method is defined in the Player class (Or a subclass of it), you would do something like the following:
    Code: Java
    1. if(channel.equalsIgnoreCase("Staff")&&!c.getRights().isStaff()){
    That if statement would check that the channel entered is equal to "staff" (ignoring case), and that the person is NOT staff.

    OfflineSoulxs

    • Member
    • ***
    • Posts: 131
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #2 on: November 15, 2015, 03:34:25 AM »
    Getting the error: variable c might not have been initialized
    Code: [Select]
    Player c;
    if(channel.equalsIgnoreCase("Staff") && !c.getRights().isStaff()){
    return;
    }
    I googled it (click) and it said i had initialize them while declaring. But i can't initialize c because it's not a number right?
    If that makes no sense, this is what i mean:
    I can't declare c as
    int c =
    Because c is a player object, not a number. So how should i fix that?

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #3 on: November 15, 2015, 04:19:33 AM »
    Right, this is why you don't copy-paste example code.
    You do not declare the Player object "c".

    That was there simply as an example of what your player object may look like. You need to use the one defined either in the class, or in the method parameters.

    OfflineSoulxs

    • Member
    • ***
    • Posts: 131
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #4 on: November 15, 2015, 04:39:53 AM »
    So how would i declare c ..
    I've tried:
    Code: [Select]
    String c = player;
    if(channel.equalsIgnoreCase("Staff") && !c.getRights().isStaff()){
    return;
    }


    These are the errors:
    Code: [Select]
    src\com\ruseps\world\content\clan\ClanChatManager.java:175: error: incompatible types: Player cannot be converted to String
            String c = player;
                       ^
    src\com\ruseps\world\content\clan\ClanChatManager.java:176: error: cannot find symbol
                    if(channel.equalsIgnoreCase("Staff") && !c.getRights().isStaff()){
                                                              ^
      symbol:   method getRights()
      location: variable c of type String
    2 errors

    It's so annoying lol.. Whenever i watch all these tutorials/read artricles i fully understand it but when i have to type it out myself it never works -.-

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #5 on: November 15, 2015, 04:56:43 AM »
    You do not declare c

    I never, once, said to.

    I said:
    Quote
    Assuming your Player object is defined as "c" and the "getRights()" method is defined in the Player class (Or a subclass of it),

    I also said here:
    Quote
    I assume getRights() is defined in the Player class, or a similar one. Use your player object (I'm not sure what you use for it) to access the method "getRights()".
    Here's an example if your Player object is "c":

    The reason for this is because, due to not having the entire ClanChatManager.java class, nor even the full method, I have to assume variables exist.

    Instead of declaring "c". You need to use the Player object that is already defined.

    OfflineSoulxs

    • Member
    • ***
    • Posts: 131
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #6 on: November 15, 2015, 06:33:14 AM »
    Well, i changed it to player, since that's how it's declared, no errors but it doesn't work.
    Code: [Select]
    package com.ruseps.world.content.clan;

    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Map.Entry;

    import com.ruseps.model.GameMode;
    import com.ruseps.model.Item;
    import com.ruseps.util.Misc;
    import com.ruseps.util.NameUtils;
    import com.ruseps.world.entity.impl.npc.NPC;
    import com.ruseps.world.entity.impl.player.Player;
    import com.ruseps.model.PlayerRights;

    /**
     * 100% Runescape clanchat system.
     * @author Gabriel Hannason
     */
    public class ClanChatManager {

    private static final String FILE_DIRECTORY = "./data/saves/clans/";

    private static ClanChat[] clans = new ClanChat[3000];

    public static ClanChat[] getClans() {
    return clans;
    }

    public static ClanChat getClanChat(int index) {
    return clans[index];
    }

    public static ClanChat getClanChatChannel(Player player) {
    for(ClanChat clan : clans) {
    if(clan == null || clan.getOwnerName() == null)
    continue;
    if(clan.getOwnerName().equals(player.getUsername())) {
    return clan;
    }
    }
    return null;
    }

    public static void init() {
    try {
    for (File file : (new File(FILE_DIRECTORY)).listFiles()) {
    if(!file.exists())
    continue;
    DataInputStream input = new DataInputStream(new FileInputStream(file));
    String name = input.readUTF();
    String owner = input.readUTF();
    int index = input.readShort();
    ClanChat clan = new ClanChat(owner, name, index);
    clan.setRankRequirements(ClanChat.RANK_REQUIRED_TO_ENTER, ClanChatRank.forId(input.read()));
    clan.setRankRequirements(ClanChat.RANK_REQUIRED_TO_KICK, ClanChatRank.forId(input.read()));
    clan.setRankRequirements(ClanChat.RANK_REQUIRED_TO_TALK, ClanChatRank.forId(input.read()));
    int totalRanks = input.readShort();
    for (int i = 0; i < totalRanks; i++) {
    clan.getRankedNames().put(input.readUTF(), ClanChatRank.forId(input.read()));
    }
    int totalBans = input.readShort();
    for (int i = 0; i < totalBans; i++) {
    clan.addBannedName(input.readUTF());
    }
    clans[index] = clan;
    input.close();
    }
    } catch (IOException exception) {
    exception.printStackTrace();
    }
    }

    public static void writeFile(ClanChat clan) {
    try {
    File file = new File(FILE_DIRECTORY + clan.getName());
    if (file.exists())
    file.createNewFile();
    DataOutputStream output = new DataOutputStream(new FileOutputStream(file));
    output.writeUTF(clan.getName());
    output.writeUTF(clan.getOwnerName());
    output.writeShort(clan.getIndex());
    output.write(clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_ENTER] != null ? clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_ENTER].ordinal() : -1);
    output.write(clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_KICK] != null ? clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_KICK].ordinal() : -1);
    output.write(clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_TALK] != null ? clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_TALK].ordinal() : -1);
    output.writeShort(clan.getRankedNames().size());
    for (Entry<String, ClanChatRank> iterator : clan.getRankedNames().entrySet()) {
    String name = iterator.getKey();
    int rank = iterator.getValue().ordinal();
    output.writeUTF(name);
    output.write(rank);
    }
    output.writeShort(clan.getBannedNames().size());
    for(String ban : clan.getBannedNames()) {
    output.writeUTF(ban);
    }
    output.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public static void save() {
    for (ClanChat clan : clans) {
    if (clan != null) {
    writeFile(clan);
    }
    }
    }

    public static void createClan(Player player) {
    player.getPacketSender().sendInterfaceRemoval();
    if(getClanChatChannel(player) != null) {
    player.getPacketSender().sendMessage("You have already created a clanchat channel.");
    return;
    }
    File file = new File(FILE_DIRECTORY + player.getUsername());
    if (file.exists())
    file.delete();
    ClanChat createdCc = create(player);
    if(createdCc != null) {
    if(player.getCurrentClanChat() == null) {
    join(player, createdCc);
    }
    player.getPacketSender().sendMessage("You now have a clanchat channel. To enter the chat, simply use your name as keyword.");
    }
    }

    public static void deleteClan(Player player) {
    player.getPacketSender().sendInterfaceRemoval();
    if (player.getCurrentClanChat() != null) {
    player.getPacketSender().sendMessage("Please leave the clanchat channel you are currently in before doing this.");
    return;
    }
    if(getClanChatChannel(player) == null) {
    player.getPacketSender().sendMessage("You have not created a clanchat channel yet.");
    return;
    }
    delete(player);
    }

    public static ClanChat create(Player player) {
    File file = new File(FILE_DIRECTORY + player.getUsername());
    if (file.exists()) {
    player.getPacketSender().sendMessage("Your clan channel is already public!");
    return null;
    }
    int index = getIndex();
    if (index == -1) { // Too many clans
    player.getPacketSender().sendMessage("An error occured! Please contact an administrator and report this.");
    return null;
    }
    clans[index] = new ClanChat(player, player.getUsername(), index);
    clans[index].getRankedNames().put(player.getUsername(), ClanChatRank.OWNER);
    writeFile(clans[index]);
    return clans[index];
    }

    public static void join(Player player, String channel) {
    if(channel == null || channel.equals("null"))
    return;
    if (player.getCurrentClanChat() != null) {
    player.getPacketSender().sendMessage("You are already in a clan channel.");
    return;
    }

    if(channel.equalsIgnoreCase("Staff") && !player.getRights().isStaff()){  // ---------------------------------------------------------------------PROBLEM IS HERE
    return;
    }

    channel = channel.toLowerCase();
    for (ClanChat clan : clans) {
    if (clan != null) {
    if(clan.getName().toLowerCase().equals(channel)) {
    join(player, clan);
    return;
    }
    }
    }
    for (ClanChat clan : clans) {
    if (clan != null) {
    if(clan.getOwnerName().toLowerCase().equals(channel)) {
    join(player, clan);
    return;
    }
    }
    }
    player.getPacketSender().sendMessage("That channel does not exist.");
    }

    public static void updateList(ClanChat clan) {
    Collections.sort(clan.getMembers(), new Comparator<Player>() {
    @Override
    public int compare(Player o1, Player o2) {
    ClanChatRank rank1 = clan.getRank(o1);
    ClanChatRank rank2 = clan.getRank(o2);
    if(rank1 == null && rank2 == null) {
    return 1;
    }
    if(rank1 == null && rank2 != null) {
    return 1;
    } else if(rank1 != null && rank2 == null) {
    return -1;
    }
    if(rank1.ordinal() == rank2.ordinal()) {
    return 1;
    }
    if(rank1 == ClanChatRank.OWNER) {
    return -1;
    } else if(rank2 == ClanChatRank.OWNER) {
    return 1;
    }
    if(rank1.ordinal() > rank2.ordinal()) {
    return -1;
    }
    return 1;
    }
    });
    for (Player member : clan.getMembers()) {
    if (member != null) {
    int childId = 29344;
    for (Player others : clan.getMembers()) {
    if (others != null) {
    ClanChatRank rank = clan.getRank(others);

    int image = -1;
    if(rank != null) {
    image = 34 + rank.ordinal();
    }

    String prefix = image >= 0 ? ("<img=" + (image) +  "> ") : "";
    member.getPacketSender().sendString(childId, prefix + others.getUsername());
    childId++;
    }
    }
    for (int i = childId; i < 29444; i++) {
    member.getPacketSender().sendString(i, "");
    }
    ClanChatRank rank = clan.getRank(member);
    if(rank != null) {
    if(rank == ClanChatRank.OWNER || rank == ClanChatRank.STAFF) {
    member.getPacketSender().sendClanChatListOptionsVisible(2); //Kick/demote/promote options
    } else if(clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_KICK] != null && rank.ordinal() >= clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_KICK].ordinal()) {
    member.getPacketSender().sendClanChatListOptionsVisible(1); //only kick option
    } else {
    member.getPacketSender().sendClanChatListOptionsVisible(0); //no options
    }
    }
    }
    }
    }

    public static void sendMessage(Player player, String message) {
    ClanChat clan = player.getCurrentClanChat();
    if (clan == null) {
    player.getPacketSender().sendMessage("You're not in a clanchat channel.");
    return;
    }
    ClanChatRank rank = clan.getRank(player);
    if(clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_TALK] != null) {
    if (rank == null || rank.ordinal() < clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_TALK].ordinal()) {
    player.getPacketSender().sendMessage("You do not have the required rank to speak in this channel.");
    return;
    }
    }
    String bracketColor = "<col=16777215>";
    String clanNameColor = "<col=255>";
    String nameColor = "@[email protected]";
    String chatColor = "<col=993D00>";
    for (Player memberPlayer : clan.getMembers()) {
    if (memberPlayer != null) {
    if(memberPlayer.getRelations().getIgnoreList().contains(player.getLongUsername()))
    continue;
    int img = player.getRights().ordinal();
    if(!player.getRights().isStaff() && !player.getRights().isMember()) {
    if(player.getGameMode() == GameMode.IRONMAN) {
    img = 33;
    } else if(player.getGameMode() == GameMode.HARDCORE_IRONMAN) {
    img = 32;
    }
    }

    String rankImg = img > 0 ? " <img="+img+"> " : " ";
    memberPlayer.getPacketSender().sendMessage("@clan:[email protected]" + bracketColor + "[" + clanNameColor + clan.getName() + bracketColor + "]" + nameColor + ""+rankImg+"" +
    NameUtils.capitalizeWords(player.getUsername()) +
    ": " + chatColor +
    NameUtils.capitalize(message));
    }
    }
    }

    public static void sendMessage(ClanChat clan, String message) {
    for (Player member : clan.getMembers()) {
    if (member != null) {
    member.getPacketSender().sendMessage(message);
    }
    }
    }

    public static void leave(Player player, boolean kicked) {
    final ClanChat clan = player.getCurrentClanChat();
    if (clan == null) {
    player.getPacketSender().sendMessage("You are not in a clanchat channel.");
    return;
    }
    player.getPacketSender().sendString(29340, "Talking in: N/A");
    player.getPacketSender().sendString(29450, "Owner: N/A");
    player.getPacketSender().sendString(29454, "Lootshare: N/A");
    player.setCurrentClanChat(null);
    clan.removeMember(player.getUsername());
    for (int i = 29344; i < 29444; i++) {
    player.getPacketSender().sendString(i, "");
    }
    player.getPacketSender().sendClanChatListOptionsVisible(0);
    updateList(clan);
    player.getPacketSender().sendMessage(kicked ? "You have been kicked from the channel." : "You have left the channel.");
    }

    private static void join(Player player, ClanChat clan) {
    if (clan.getOwnerName().equals(player.getUsername())) {
    if (clan.getOwner() == null) {
    clan.setOwner(player);
    }
    clan.giveRank(player, ClanChatRank.OWNER);
    }
    player.getPacketSender().sendMessage("Attempting to join channel...");
    if (clan.getMembers().size() >= 100) {
    player.getPacketSender().sendMessage("This clan channel is currently full.");
    return;
    }
    if(clan.isBanned(player.getUsername())) {
    player.getPacketSender().sendMessage("You're currently banned from using this channel. Bans expire every 20 minutes.");
    return;
    }
    checkFriendsRank(player, clan, false);
    ClanChatRank rank = clan.getRank(player);
    if (player.getRights().isStaff()) {
    if(rank == null || rank != ClanChatRank.OWNER) {
    rank = ClanChatRank.STAFF;
    clan.giveRank(player, ClanChatRank.STAFF);
    }
    } else {
    if(rank != null && rank == ClanChatRank.STAFF) {
    clan.giveRank(player, null);
    }
    }
    if (clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_ENTER] != null) {
    if (rank == null || clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_ENTER].ordinal() > rank.ordinal()) {
    player.getPacketSender().sendMessage("Your rank is not high enough to enter this channel.");
    return;
    }
    }
    player.setCurrentClanChat(clan);
    player.setClanChatName(clan.getName());
    String clanName = NameUtils.capitalizeWords(clan.getName());
    clan.addMember(player);
    player.getPacketSender().sendString(29340, "Talking in: @[email protected]" + clanName);
    player.getPacketSender().sendString(29450, "Owner: " + NameUtils.capitalizeWords(clan.getOwnerName()));
    player.getPacketSender().sendString(29454, "Lootshare: "+getLootshareStatus(clan));
    player.getPacketSender().sendMessage("Now talking in "+clan.getOwnerName()+"'s channel.");
    player.getPacketSender().sendMessage("To talk start each line of chat with the / symbol.");
    updateList(clan);
    }

    public static void checkFriendsRank(Player player, ClanChat chat, boolean update) {
    ClanChatRank rank = chat.getRank(player);
    if(rank == null) {
    if(chat.getOwner() != null && chat.getOwner().getRelations().isFriendWith(player.getUsername())) {
    chat.giveRank(player, ClanChatRank.FRIEND);
    if(update) {
    updateList(chat);
    }
    }
    } else {
    if(rank == ClanChatRank.FRIEND && chat.getOwner() != null && !chat.getOwner().getRelations().isFriendWith(player.getUsername())) {
    chat.giveRank(player, null);
    if(update) {
    updateList(chat);
    }
    }
    }
    }

    public static void delete(Player player) {
    ClanChat clan = getClanChatChannel(player);
    File file = new File(FILE_DIRECTORY + clan.getName());
    for (Player member : clan.getMembers()) {
    if (member != null) {
    leave(member, true);
    member.setClanChatName("");
    }
    }
    if(player.getClanChatName().equalsIgnoreCase(clan.getName())) {
    player.setClanChatName("");
    }
    player.getPacketSender().sendMessage("Your clanchat channel was successfully deleted.");
    clans[clan.getIndex()] = null;
    file.delete();
    }

    public static void setName(Player player, String newName) {
    final ClanChat clan = getClanChatChannel(player);
    if (clan == null) {
    player.getPacketSender().sendMessage("You need to have a clan channel to do this.");
    return;
    }
    if(newName.length() == 0)
    return;
    if (newName.length() > 12)
    newName = newName.substring(0, 11);
    if(new File(FILE_DIRECTORY + newName).exists()) {
    player.getPacketSender().sendMessage("That clanchat name is already taken.");
    return;
    }
    if(clan.getLastAction().elapsed(5000) || player.getRights().isStaff()) {
    new File(FILE_DIRECTORY + clan.getName()).delete();
    clan.setName(NameUtils.capitalizeWords(newName));
    for(Player member : clan.getMembers()) {
    if(member == null)
    continue;
    member.setClanChatName(clan.getName());
    member.getPacketSender().sendString(29340, "Talking in: @[email protected]" + clan.getName());
    }
    clanChatSetupInterface(player, false);
    writeFile(clan);
    clan.getLastAction().reset();
    } else {
    player.getPacketSender().sendMessage("You need to wait a few seconds between every clanchat action.");
    }
    }

    public static void kick(Player player, Player target) {
    ClanChat clan = player.getCurrentClanChat();
    if (clan == null) {
    player.getPacketSender().sendMessage("You're not in a clan channel.");
    return;
    }
    final ClanChatRank rank = clan.getRank(player);
    if (rank == null || rank != ClanChatRank.STAFF && clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_KICK] != null && rank.ordinal() < clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_KICK].ordinal()) {
    player.getPacketSender().sendMessage("You do not have the required rank to kick this player.");
    return;
    }
    for (Player member : clan.getMembers()) {
    if (member != null && member.equals(target)) {
    ClanChatRank memberRank = clan.getRank(member);
    if (memberRank != null) {
    if(memberRank == ClanChatRank.STAFF) {
    player.getPacketSender().sendMessage("That player cannot be kicked.");
    break;
    }
    if(rank.ordinal() < memberRank.ordinal()) {
    player.getPacketSender().sendMessage("You cannot kick a player who has a higher rank than you!");
    break;
    }
    }
    clan.addBannedName(member.getUsername());
    leave(member, true);
    sendMessage(player.getCurrentClanChat(), "<col=16777215>[<col=255>"+clan.getName() +"<col=16777215>]<col=3300CC> "+member.getUsername()+" has been kicked from the channel by "+player.getUsername()+".");
    break;
    }
    }
    }

    public static void handleMemberOption(Player player, int index, int menuId) {
    if ((player.getCurrentClanChat() == null || !player.getCurrentClanChat().getOwnerName().equals(player.getUsername())) && menuId != 1) {
    player.getPacketSender().sendMessage("Only the clanchat owner can do that.");
    return;
    }
    Player target = getPlayer(index, player.getCurrentClanChat());
    if(target == null || target.equals(player)) {
    return;
    }
    switch(menuId) {
    case 8:
    case 7:
    case 6:
    case 5:
    case 4:
    case 3:
    ClanChatRank rank = ClanChatRank.forMenuId(menuId);
    ClanChatRank targetRank = player.getCurrentClanChat().getRank(target);
    if(targetRank != null) {
    if(targetRank == rank) {
    player.getPacketSender().sendMessage("That player already has that rank.");
    return;
    }
    if(targetRank == ClanChatRank.STAFF) {
    player.getPacketSender().sendMessage("That player cannot be promoted or demoted.");
    return;
    }
    }
    if(player.getCurrentClanChat().getLastAction().elapsed(5000) || player.getRights().isStaff()) {
    player.getCurrentClanChat().giveRank(target, rank);
    updateList(player.getCurrentClanChat());
    sendMessage(player.getCurrentClanChat(), "<col=16777215>[<col=255>"+player.getCurrentClanChat().getName() +"<col=16777215>]<col=3300CC> "+target.getUsername()+" has been given the rank: "+Misc.formatText(rank.name().toLowerCase())+".");
    player.getCurrentClanChat().getLastAction().reset();
    } else {
    player.getPacketSender().sendMessage("You need to wait a few seconds between every clanchat action.");
    }
    break;
    case 2:
    targetRank = player.getCurrentClanChat().getRank(target);
    if(targetRank == null) {
    player.getPacketSender().sendMessage("That player has no rank.");
    return;
    }
    if(targetRank == ClanChatRank.STAFF) {
    player.getPacketSender().sendMessage("That player cannot be promoted or demoted.");
    return;
    }
    if(player.getCurrentClanChat().getLastAction().elapsed(5000) || player.getRights().isStaff()) {
    player.getCurrentClanChat().getRankedNames().remove(target.getUsername());
    checkFriendsRank(target, player.getCurrentClanChat(), false);
    updateList(player.getCurrentClanChat());
    sendMessage(player.getCurrentClanChat(), "<col=16777215>[<col=255>"+player.getCurrentClanChat().getName() +"<col=16777215>]<col=3300CC> "+target.getUsername()+" has been demoted from his rank.");
    player.getCurrentClanChat().getLastAction().reset();
    } else {
    player.getPacketSender().sendMessage("You need to wait a few seconds between every clanchat action.");
    }
    break;
    case 1:
    kick(player, target);
    break;
    }
    }

    public static boolean dropShareLoot(Player player, NPC npc, Item itemDropped) {
    /*ClanChat clan = player.getFields().getClanChat();
    if (clan != null) {
    boolean received = false;
    List<Player> players = getPlayersWithinPosition(clan, npc.getPosition());
    String green = "<col=" + ClanChatMessageColor.GREEN.getRGB()[player.getFields().rgbIndex] + ">";
    if (clan.isItemSharing() && itemDropped.getId() != 995) {
    Player rewarded = players.size() > 0 ? players.get(MathUtils.random(players.size() - 1)) : null;
    if (rewarded != null) {
    rewarded.getPacketSender().sendMessage(green + "You have received " + itemDropped.getAmount() + "x " + itemDropped.getDefinition().getName() + ".");
    received = true;
    }
    }
    if (clan.isCoinSharing() && itemDropped.getId() == 995) {
    for (Item drop : npc.getDrops()) {
    if ((drop.getDefinition().getValue() * drop.getAmount()) < 50000) {
    GroundItem groundItem = new GroundItem(drop, npc.getPosition().copy());
    GameServer.getWorld().register(groundItem, player);
    continue;
    }
    int amount = (int) (ItemDefinition.forId(drop.getId()).getValue() / players.size());
    Item split = new Item(995, amount);
    for (Player member : players) {
    GroundItem groundItem = new GroundItem(split.copy(), npc.getPosition().copy());
    GameServer.getWorld().register(groundItem, member);
    member.getPacketSender().sendMessage(green + "You have received " + amount + "x " + split.getDefinition().getName() + " as part of a split drop.");
    }
    }
    } else if(!clan.isItemSharing() && !clan.isCoinSharing() || !received)
    return false;
    } else
    return false;*/
    return false;
    }

    public static void toggleLootShare(Player player) {
    final ClanChat clan = player.getCurrentClanChat();
    if (clan == null) {
    player.getPacketSender().sendMessage("You're not in a clan channel.");
    return;
    }
    if(!player.getRights().isStaff()) {
    if(clan.getOwner() == null)
    return;
    if (!clan.getOwner().equals(player)) {
    player.getPacketSender().sendMessage("Only the owner of the channel has the power to do this.");
    return;
    }
    }
    if(clan.getLastAction().elapsed(5000) || player.getRights().isStaff()) {
    clan.setLootShare(!clan.getLootShare());
    sendMessage(clan, "<col=16777215>[<col=255>"+clan.getName() +"<col=16777215>] <col=3300CC>"+player.getUsername()+" has "+(clan.getLootShare() ? "enabled" : "disabled")+" Lootshare.");
    for (Player member : clan.getMembers()) {
    if (member != null) {
    member.getPacketSender().sendString(29454, "Lootshare: "+getLootshareStatus(clan));
    }
    }
    clan.getLastAction().reset();
    } else {
    player.getPacketSender().sendMessage("You need to wait a few seconds between every clanchat action.");
    }
    }

    private static String getLootshareStatus(ClanChat clan) {
    return clan.getLootShare() ? "@[email protected]" : "Off";
    }

    private static int getIndex() {
    for (int i = 0; i < clans.length; i++) {
    if (clans[i] == null) {
    return i;
    }
    }
    return -1;
    }

    public static boolean handleClanChatSetupButton(Player player, int id) {
    if(player.getInterfaceId() == 40172) {
    final ClanChat clan = getClanChatChannel(player);
    if (clan == null) {
    return true;
    }
    switch(id) {
    case -18281:
    case -17529:
    case -17530:
    case -17531:
    case -17532:
    case -17533:
    case -17534:
    case -17535:
    case -17536:
    int l = -17529 - id;
    clan.setRankRequirements(ClanChat.RANK_REQUIRED_TO_ENTER, id == -18281 ? null : ClanChatRank.forId(l));
    player.getPacketSender().sendMessage("You have changed your clanchat channel's settings.");
    if (clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_ENTER] != null) {
    for(Player member : clan.getMembers()) {
    if(member == null)
    continue;
    ClanChatRank rank = clan.getRank(member);
    if (rank == null || clan.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_ENTER].ordinal() > rank.ordinal() && rank != ClanChatRank.STAFF) {
    member.getPacketSender().sendMessage("Your rank is not high enough to be in this channel.");
    leave(member, false);
    player.getPacketSender().sendMessage("@[email protected]! Changing that setting kicked the player "+member.getUsername()+" from the chat because").sendMessage("@[email protected] they do not have the required rank to be in the chat.");;
    }
    }
    }
    clanChatSetupInterface(player, false);
    writeFile(clan);
    return true;
    case -18278:
    case -17519:
    case -17520:
    case -17521:
    case -17522:
    case -17523:
    case -17524:
    case -17525:
    case -17526:
    l = -17519 - id;
    clan.setRankRequirements(ClanChat.RANK_REQUIRED_TO_TALK, id == -18278 ? null : ClanChatRank.forId(l));
    player.getPacketSender().sendMessage("You have changed your clanchat channel's settings.");
    clanChatSetupInterface(player, false);
    writeFile(clan);
    return true;
    case -18275:
    case -17510:
    case -17511:
    case -17512:
    case -17513:
    case -17514:
    case -17515:
    l = (-17510 - id) + 1;
    clan.setRankRequirements(ClanChat.RANK_REQUIRED_TO_KICK, id == -18275 ? null : ClanChatRank.forId(l));
    player.getPacketSender().sendMessage("You have changed your clanchat channel's settings.");
    clanChatSetupInterface(player, false);
    updateList(clan);
    writeFile(clan);
    return true;
    }
    }
    return false;
    }

    public static void clanChatSetupInterface(Player player, boolean check) {
    player.getPacketSender().sendInterfaceRemoval();
    ClanChat channel = getClanChatChannel(player);
    if(check) {
    if(channel == null) {
    player.getPacketSender().sendMessage("You have not created a clanchat channel yet.");
    return;
    }
    }
    player.getPacketSender().sendString(47814, channel.getName());
    if (channel.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_ENTER] == null) {
    player.getPacketSender().sendString(47815, "Anyone");
    } else {
    player.getPacketSender().sendString(47815, Misc.formatText(channel.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_ENTER].name().toLowerCase())+"+");
    }

    if (channel.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_TALK] == null) {
    player.getPacketSender().sendString(47816, "Anyone");
    } else {
    player.getPacketSender().sendString(47816, Misc.formatText(channel.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_TALK].name().toLowerCase())+"+");
    }

    if (channel.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_KICK] == null) {
    player.getPacketSender().sendString(47817, "Only me");
    } else {
    player.getPacketSender().sendString(47817, Misc.formatText(channel.getRankRequirement()[ClanChat.RANK_REQUIRED_TO_KICK].name().toLowerCase())+"+");
    }

    player.getPacketSender().sendInterface(40172);
    }

    public static void handleLogin(Player player) {
    resetInterface(player);
    if(player.getClanChatName() == null || player.getClanChatName().equals("null")) {
    if(Misc.getMinutesPlayed(player) <= 15) {
    player.getPacketSender().sendMessage("<img=10> <col=660099>Feel free to join the 'Help' clanchat channel to talk to other players.");
    }
    }
    ClanChatManager.join(player, player.getClanChatName());
    }

    public static void resetInterface(Player player) {
    player.getPacketSender().sendString(29340, "Talking in: N/A");
    player.getPacketSender().sendString(29450, "Owner: N/A");
    player.getPacketSender().sendString(29454, "Lootshare: N/A");
    for (int i = 29344; i < 29444; i++) {
    player.getPacketSender().sendString(i, "");
    }
    }

    public static Player getPlayer(int index, ClanChat clan) {
    int clanIndex = 0;
    for (Player members : clan.getMembers()) {
    if (members != null) {
    if(clanIndex == index) {
    return members;
    }
    clanIndex++;
    }
    }
    return null;
    }
    }


    It still lets regular players join a clan chat called Staff

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #7 on: November 15, 2015, 06:40:32 AM »
    Print out the value of isStaff, on both a non-staff and a staff account.
    Code: Java
    1. System.out.println("Player Staff: "+ player.getRights().isStaff());

    OfflineSoulxs

    • Member
    • ***
    • Posts: 131
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #8 on: November 15, 2015, 06:42:32 AM »
    I don't know what you mean. I'll post the code of the isStaff method and if that's not of any use tell me how i print that value out. Because i know what it does but where do i put it :P
    Code: [Select]
    package com.ruseps.model;

    import com.google.common.collect.ImmutableSet;
    import com.google.common.collect.Sets;


    /**
     * Represents a player's privilege rights.
     * @author Gabriel Hannason
     */

    public enum PlayerRights {

    /*
    * A regular member of the server.
    */
    PLAYER(-1, null, 1, 1),
    /*
    * A moderator who has more privilege than other regular members and donators.
    */
    MODERATOR(-1, "<col=20B2AA><shad=0>", 1, 1),

    /*
    * The second-highest-privileged member of the server.
    */
    ADMINISTRATOR(-1, "<col=FFFF64><shad=0>", 1, 1),

    /*
    * Controls the staff team
    */
    HEAD_ADMINISTRATOR(-1, "<col=FFFF64><shad=0>", 1, 1),

    /*
    * The highest-privileged member of the server
    */
    OWNER(-1, "<col=B40404>", 1, 1),

    /*
    * The Developer of the server, has same rights as the owner.
    */
    DEVELOPER(-1, "<shad=B40404>", 1, 1),



    /*
    * A member who has donated to the server.
    */
    BRONZE_MEMBER(60, "<shad=FF7F00>", 1.5, 1),
    SILVER_MEMBER(40, "<shad=0><col=787878>", 1.5, 1.25),
     GOLD_MEMBER(20, "<col=D9D919><shad=0>", 2, 1.5),
    PLATINUM_MEMBER(10, "<shad=697998>", 2.5, 1.7),
    DIAMOND_MEMBER(0, "<shad=0EBFE9>", 3, 2),

    /*
    * A member who has the ability to help people better.
    */
    SUPPORT(-1, "<col=FF0000><shad=0>", 1, 1),

    /*
    * A member who has been with the server for a long time.
    */
    VETERAN(30, "<col=CD661D>", 1, 1);

    PlayerRights(int yellDelaySeconds, String yellHexColorPrefix, double loyaltyPointsGainModifier, double experienceGainModifier) {
    this.yellDelay = yellDelaySeconds;
    this.yellHexColorPrefix = yellHexColorPrefix;
    this.loyaltyPointsGainModifier = loyaltyPointsGainModifier;
    this.experienceGainModifier = experienceGainModifier;
    }

    private static final ImmutableSet<PlayerRights> STAFF = Sets.immutableEnumSet(SUPPORT, MODERATOR, ADMINISTRATOR, HEAD_ADMINISTRATOR, OWNER, DEVELOPER); ------ENUM
    private static final ImmutableSet<PlayerRights> MEMBERS = Sets.immutableEnumSet(BRONZE_MEMBER, SILVER_MEMBER, GOLD_MEMBER, PLATINUM_MEMBER, DIAMOND_MEMBER);

    /*
    * The yell delay for the rank
    * The amount of seconds the player with the specified rank must wait before sending another yell message.
    */
    private int yellDelay;
    private String yellHexColorPrefix;
    private double loyaltyPointsGainModifier;
    private double experienceGainModifier;

    public int getYellDelay() {
    return yellDelay;
    }

    /*
    * The player's yell message prefix.
    * Color and shadowing.
    */

    public String getYellPrefix() {
    return yellHexColorPrefix;
    }

    /**
    * The amount of loyalty points the rank gain per 4 seconds
    */
    public double getLoyaltyPointsGainModifier() {
    return loyaltyPointsGainModifier;
    }

    public double getExperienceGainModifier() {
    return experienceGainModifier;
    }
    public boolean isStaff() { // -------------------------------------------------------------------------Method
    return STAFF.contains(this);
    }
    public boolean isMember() {
    return MEMBERS.contains(this);
    }

    /**
    * Gets the rank for a certain id.
    *
    * @param idThe id (ordinal()) of the rank.
    * @returnrights.
    */
    public static PlayerRights forId(int id) {
    for (PlayerRights rights : PlayerRights.values()) {
    if (rights.ordinal() == id) {
    return rights;
    }
    }
    return null;
    }
    }


    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #9 on: November 15, 2015, 07:20:48 AM »
    I just gave you the code to print it out... You don't place it in PlayerRights. It goes in the ClanChatManager
    Place it above the if statement that checks the rights.

    Now when a player joins a clan chat it will print out "Player Staff: true" or "Player Staff: false".
    tell me what it says when a non staff member joins the chat, and when a staff member joins the chat.

    OfflineSoulxs

    • Member
    • ***
    • Posts: 131
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #10 on: November 15, 2015, 07:48:53 AM »
    EDIT: It worked, i'm a dumbass. I checked to see if a player can join with the bronze donator crown, but he was in fact a developer rank.
    My bad, thanks!


    « Last Edit: November 15, 2015, 07:55:14 AM by Soulxs »

    OfflineRoar337

    • Member
    • ****
    • Posts: 252
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #11 on: November 15, 2015, 10:08:25 PM »
    @soulxs

    Hi there even though your problem has been fixed and you yourself will most likely NEVER see this <-- lulz why do i bother
    You seem to be having a bit of trouble with java if i had to guess you are new to it and looking to learn so you basically jumped into the deep end
    I did that, it worked great(in about 6-7 years time) lol i recommend you go look at some short youtube videos based on object oriented programming in this case specifically java
    You should then learn a little bit about:

    - Java docs
    - Variables
    - Api <- Has to do with all the methods that you have been probably blindly manipulating up until now
    - Basic math in java
    - Code conventions <-- grammar for nerds and programmers
    - Common compiler errors
    - A good IDE(Integrated development environment erm i think that's the acronym) such as net beans or eclipse
    - Data storage types int long double string bool etc...

    Additionally if your going to work on rsps servers you should look into:
    - The rs protocol <-- the way clients talk to servers but data in transit is protected this will help you a lot if you ever deal with packets.

    I know this is a pain and honestly i could go on but at the end of it all you would beat yourself to death with your shoe because you realized how lost you were!

    Or im completely wrong and have made a terrible misconception in which case *Meep* <- lul
    Code: [Select]
    for(int i=0; i < 2147483647; i++) {
    doFacedesk();
    }

    OfflineSoulxs

    • Member
    • ***
    • Posts: 131
    • Thanks: +0/-0
      • View Profile
    Re: Staff Clan Chat // Regular players cannot join.
    « Reply #12 on: November 16, 2015, 09:47:17 AM »
    Im not on moparscape to get spoonfed. Even if i dont have any questions i still check server help reguraly to see if i can help others or learn from the problems others had.

    Thanks for the advice and ill look into it!

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal