Thread: [PI] Unmute/Unipmute/Unipban

Results 1 to 3 of 3
  1. #1 [PI] Unmute/Unipmute/Unipban 
    Registered Member Rojeh's Avatar
    Join Date
    Jun 2012
    Posts
    353
    Thanks given
    7
    Thanks received
    20
    Rep Power
    75
    My commands.java was bugged . did a quick fix for it and now the commands works fine -- Problem solved ---


    Hello ,

    The following commands :

    *unmute
    *unipmute
    *unipban

    Doesn't seem to work.. please help me


    Commands :


    Un-mute~
    if (playerCommand.startsWith("unmute")) {
    try {
    String playerToBan = playerCommand.substring(7);
    Connection.unMuteUser(playerToBan);
    } catch (Exception e) {
    c.sendMessage("Player is probably offline.");
    }
    }
    Un-IPmute~

    if (playerCommand.startsWith("unipmute")) {
    try {
    String playerToBan = playerCommand.substring(9);
    for (int i = 0; i < Config.MAX_PLAYERS; i++) {
    if (Server.playerHandler.players[i] != null) {
    if (Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
    Connection.unIPMuteUser(Server.playerHandler.playe rs[i].connectedFrom);
    c.sendMessage("You have un IP-muted the user: " + Server.playerHandler.players[i].playerName);
    break;
    }
    }
    }
    } catch (Exception e) {
    c.sendMessage("Player is probably offline.");
    }
    }
    Un-IPban~

    if (playerCommand.startsWith("unipban")) {
    try {
    String playerToBan = playerCommand.substring(9);
    for (int i = 0; i < Config.MAX_PLAYERS; i++) {
    if (Server.playerHandler.players[i] != null) {
    if (Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
    Connection.unIPBanUser(Server.playerHandler.player s[i].connectedFrom);
    c.sendMessage("You have un-IPbanned the user: " + Server.playerHandler.players[i].playerName);
    break;
    }
    }
    }
    } catch (Exception e) {
    c.sendMessage("Player is probably offline.");
    }
    }

    Connection.java :

    package server;

    import java.io.BufferedReader;

    import java.io.BufferedWriter;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import server.game.players.Client;

    /**
    * Connection Check Class
    *
    * @author Ryan / Lmctruck30
    *
    */

    public class Connection {

    public static ArrayList <String>bannedIps = new ArrayList<String> ();
    public static ArrayList <String>bannedNames = new ArrayList<String> ();
    public static ArrayList <String>mutedIps = new ArrayList<String> ();
    public static ArrayList <String>mutedNames = new ArrayList<String> ();
    public static ArrayList <String>loginLimitExceeded = new ArrayList<String> ();
    public static ArrayList <String>starterReceived1 = new ArrayList<String> ();


    /**
    * Adds the banned usernames and ips from the text file to the ban list
    **/
    public static void initialize() {
    banUsers();
    banIps();
    muteUsers();
    muteIps();
    appendStarters();
    }

    /**
    * Handles 2 starters per IP
    **/
    public static boolean hasReceived1stStarter(String IP) {
    if(starterReceived1.contains(IP)) {
    return true;
    }
    return false;
    }

    public static void addIpToStarter1(String IP) {
    starterReceived1.add(IP);
    addIpToStarterList1(IP);
    }

    public static void appendStarters() {
    try {
    BufferedReader in = new BufferedReader(new FileReader("./Data/starters/FirstStarterRecieved.txt"));
    String data = null;
    try {
    while ((data = in.readLine()) != null) {
    starterReceived1.add(data);
    }
    } finally {
    in.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public static void addIpToStarterList1(String Name) {
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter("./Data/starters/FirstStarterRecieved.txt", true));
    try {
    out.newLine();
    out.write(Name);
    } finally {
    out.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    /**
    * Adding Name To List
    */
    public static void addIpToLoginList(String IP) {
    loginLimitExceeded.add(IP);
    }

    /**
    * Remove Ip From List
    */
    public static void removeIpFromLoginList(String IP) {
    loginLimitExceeded.remove(IP);
    }

    /**
    * Clear Name List
    */
    public static void clearLoginList() {
    loginLimitExceeded.clear();
    }

    public static boolean checkLoginList(String IP) {
    loginLimitExceeded.add(IP);
    int num = 0;
    for(String ips : loginLimitExceeded) {
    if(IP.equals(ips)) {
    num++;
    }
    }
    if(num > 5) {
    return true;
    }
    return false;
    }

    public static void unMuteUser(String name) {
    mutedNames.remove(name);
    deleteFromFile("./Data/bans/UsersMuted.txt", name);
    }

    public static void unIPMuteUser(String name) {
    mutedIps.remove(name);
    deleteFromFile("./Data/bans/IpsMuted.txt", name);
    }

    public static void unIPBanUser(String name) {
    bannedIps.remove(name);
    deleteFromFile("./Data/bans/IpsBanned.txt", name);
    }

    /**
    * Adding Ban IP
    **/
    public static void addIpToBanList(String IP) {
    bannedIps.add(IP);
    }

    public static void addIpToMuteList(String IP) {
    mutedIps.add(IP);
    addIpToMuteFile(IP);
    }


    /**
    * Removing Ban IP
    **/
    public static void removeIpFromBanList(String IP) {
    bannedIps.remove(IP);
    }

    /**
    * Contains Ban IP
    **/
    public static boolean isIpBanned(String IP) {
    if(bannedIps.contains(IP)) {
    return true;
    }
    return false;
    }


    /**
    * Adding banned username
    **/
    public static void addNameToBanList(String name) {
    bannedNames.add(name.toLowerCase());
    }

    public static void addNameToMuteList(String name) {
    mutedNames.add(name.toLowerCase());
    addUserToFile(name);
    }


    /**
    * Removing banned username
    **/
    public static void removeNameFromBanList(String name) {
    bannedNames.remove(name.toLowerCase());
    deleteFromFile("./Data/bans/UsersBanned.txt", name);
    }

    public static void removeNameFromMuteList(String name) {
    mutedNames.remove(name.toLowerCase());
    deleteFromFile("./Data/bans/UsersMuted.txt", name);
    }

    public static void deleteFromFile(String file, String name) {
    try {
    BufferedReader r = new BufferedReader(new FileReader(file));
    ArrayList<String> contents = new ArrayList<String>();
    while(true) {
    String line = r.readLine();
    if(line == null) {
    break;
    } else {
    line = line.trim();
    }
    if(!line.equalsIgnoreCase(name)) {
    contents.add(line);
    }
    }
    r.close();
    BufferedWriter w = new BufferedWriter(new FileWriter(file));
    for(String line : contents) {
    w.write(line, 0, line.length());
    w.newLine();
    }
    w.flush();
    w.close();
    } catch (Exception e) {}
    }

    /**
    * Contains banned username
    **/
    public static boolean isNamedBanned(String name) {
    if(bannedNames.contains(name.toLowerCase())) {
    return true;
    }
    return false;
    }


    /**
    * Reads all usernames from text file then adds them all to the ban list
    **/
    public static void banUsers() {
    try {
    BufferedReader in = new BufferedReader(new FileReader("./Data/bans/UsersBanned.txt"));
    String data = null;
    try {
    while ((data = in.readLine()) != null) {
    addNameToBanList(data);
    }
    } finally {
    in.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public static void muteUsers() {
    try {
    BufferedReader in = new BufferedReader(new FileReader("./Data/bans/UsersMuted.txt"));
    String data = null;
    try {
    while ((data = in.readLine()) != null) {
    mutedNames.add(data);
    }
    } finally {
    in.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    /**
    * Reads all the Ips from text file then adds them all to ban list
    **/
    public static void banIps() {
    try {
    BufferedReader in = new BufferedReader(new FileReader("./Data/bans/IpsBanned.txt"));
    String data = null;
    try {
    while ((data = in.readLine()) != null) {
    addIpToBanList(data);
    }
    } finally {
    in.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public static void muteIps() {
    try {
    BufferedReader in = new BufferedReader(new FileReader("./Data/bans/IpsMuted.txt"));
    String data = null;
    try {
    while ((data = in.readLine()) != null) {
    mutedIps.add(data);
    }
    } finally {
    in.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    /**
    * Writes the username into the text file - when using the ::ban playername command
    **/
    public static void addNameToFile(String Name) {
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter("./Data/bans/UsersBanned.txt", true));
    try {
    out.newLine();
    out.write(Name);
    } finally {
    out.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public static void addUserToFile(String Name) {
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter("./Data/bans/UsersMuted.txt", true));
    try {
    out.newLine();
    out.write(Name);
    } finally {
    out.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }





    /**
    * Writes the IP into the text file - use ::ipban username
    **/
    public static void addIpToFile(String Name) {
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter("./Data/bans/IpsBanned.txt", true));
    try {
    out.newLine();
    out.write(Name);
    } finally {
    out.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public static void addIpToMuteFile(String Name) {
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter("./Data/bans/IpsMuted.txt", true));
    try {
    out.newLine();
    out.write(Name);
    } finally {
    out.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public static boolean isMuted(Client c) {
    return mutedNames.contains(c.playerName) || mutedIps.contains(c.connectedFrom);

    }


    }

    Please help me
    • If it been done before you can do it too!
    • We're all humans, built from the same resources by different layouts and schemes.
    • Nobody is perfect, everyone has their own defects and disabilities.
    • Choose to be kind, not because you have to but because you understand how it feels to be treated bad.
    • Be against racism regardless of how you were raised because nobody loves feeling odd and not belonging.
      If any of the above inspires you make sure to pass it on
    Reply With Quote  
     

  2. #2  
    Registered Member Rojeh's Avatar
    Join Date
    Jun 2012
    Posts
    353
    Thanks given
    7
    Thanks received
    20
    Rep Power
    75
    bump
    • If it been done before you can do it too!
    • We're all humans, built from the same resources by different layouts and schemes.
    • Nobody is perfect, everyone has their own defects and disabilities.
    • Choose to be kind, not because you have to but because you understand how it feels to be treated bad.
    • Be against racism regardless of how you were raised because nobody loves feeling odd and not belonging.
      If any of the above inspires you make sure to pass it on
    Reply With Quote  
     

  3. #3  
    Registered Member Rojeh's Avatar
    Join Date
    Jun 2012
    Posts
    353
    Thanks given
    7
    Thanks received
    20
    Rep Power
    75
    bump
    • If it been done before you can do it too!
    • We're all humans, built from the same resources by different layouts and schemes.
    • Nobody is perfect, everyone has their own defects and disabilities.
    • Choose to be kind, not because you have to but because you understand how it feels to be treated bad.
    • Be against racism regardless of how you were raised because nobody loves feeling odd and not belonging.
      If any of the above inspires you make sure to pass it on
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PI] Unmute Command
    By JusticeHewitt in forum Help
    Replies: 4
    Last Post: 07-24-2011, 02:26 AM
  2. [PI] Unmute Command [PI]
    By Sillhouette in forum Help
    Replies: 2
    Last Post: 04-23-2011, 12:23 PM
  3. Replies: 2
    Last Post: 07-19-2010, 07:58 PM
  4. [Delta] Unmute/ Unipmute [NOOB EASY]
    By Jean in forum Tutorials
    Replies: 25
    Last Post: 06-06-2009, 03:40 PM
  5. Replies: 4
    Last Post: 03-13-2009, 01:44 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •