Solved [RELEVANT TO CATEGORY] MC Pro Hosting Port

Discussion in 'Plugin Development' started by BlueMustache, May 17, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    BlueMustache

    Hello Everybody,
    I had a question regarding something probably very simple.
    When I call getPort on Bukkit, it returns the integer of the port it is running on.
    I am integrating MCProHost Support for my plugin.
    Their rule is simple.
    If your server port is 1234, then if your say need dynmap, you set its port to 2341.
    I don't know what I would google to figure out how to do this.
    Basically rearrange the number so they all move up one, and the first number is put at the end.
    Thanks!
    Please respond asap.
     
  2. Offline

    rfsantos1996

    Why not getPort() + new Random().nextInt(4000);
     
  3. Offline

    caseif

    The only way I could think of would be to convert the port to a string, split that into a char[], and then rearrange it manually and parse it back into an int. There's probably some tricky arithmetic you could do instead, but I'm not clever enough to figure it out. :p
     
    BlueMustache likes this.
  4. Offline

    BlueMustache


    Good idea.
    Any links?


    Not exactly what I'm looking for.
    I don't want it to be random.
    I want it to be logical.

    This is the link to the rule.
    https://clients.mcprohosting.com/knowledgebase/43/How-to-Set-Up-DynMap.html

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  5. Offline

    xize

    hmm not 100% if its possible what I'm intended to do:

    Code:
        public String getPort(String port) {
            char[] chars = port.toCharArray();
            List<Integer> numbers = new ArrayList<Integer>();
            for(char c : chars) {
                if(Character.isDigit(c)) {
                    int i = Integer.parseInt(""+c);
                    numbers.add(i);
                }
            }
            Collections.sort(numbers); //due the comperator for Integers it will or show from high to low, or form low to high.
            String newport = null;
            for(int i : numbers) {
                newport += i;
            }
            return newport;
        }
     
    
     
    BlueMustache likes this.
  6. Offline

    BlueMustache

    xize

    This looks like it'll work.
    So I input the port number, in the format 1234, and it will give me 2341 as an integer?
     
  7. Offline

    xize

    BlueMustache
    I think it does, also for duplicates it should work (I think), but about the newport = null; I might made a error.
     
  8. Offline

    BlueMustache


    Thanks so much!
    I can't test this right now, but if it works how you say it does, its good to me.
    - Blue
     
  9. Offline

    Azubuso

    xize Yeah, the output of that with "newport = null" would be, (if input was 1234) null1234, and also, that sniplet wouldn't work. What are you trying to achieve with Collections.sort exactly?

    EDIT: Sorry, I meant to post the code I used for this
    PHP:
    public String getPort(String port) {
        
    char one port.charAt(0);
        
    char two port.charAt(port.length()-1);
        
    port port.substring(1port.length()-1);
        
    port two port one;
        return 
    port;
    }
     
  10. Offline

    xize

    Azubuso

    with Collections.sort() I want to shuffle the ordering based on the Comperator atleast if I understanded good how a Comperator works so that means for example if a normal List has:

    get(0) = 1
    get(1) = 2
    get(2) = 10

    it would be:
    get(0) = 10;
    get(1) = 2;
    get(2) = 1;

    but perhaps this is not needed if the ordering already is as this as natural ordering but I'm not sure.
     
  11. Offline

    rsod

    If you want it to be logical then why not use something less complicated like server port = 1234, and dyndns map is on 1234+5000, which is 6234. Seems to be logical enough and it definitely prevents collisions, depart from your method. Or, say, you can just +10000, even simplier, server is on 1234, map is on 11234. Don't think you're going to run more then 10k servers on the same ip
     
  12. Offline

    Azubuso

    xize Collections.sort() by default sorts them in ascending order, so doing it on say, the array [1,2,3,4], would return a value that doesn't differ from its original. In your code snippet the actual return is not different from the original, is what I'm saying.
     
  13. Offline

    BlueMustache

    Thank you everyone!
    I will try all of your ideas.

    Actually.
    I tried all you guys' methods.
    None of them worked right.
    When I tried the default 25565.
    With Azubuso's method, it came out the closest with 55562. Not quite right though.
    With xize's method, it came out as null25556. Which I sifted into 25556, which is not what I want.
    Does anyone know how I can fix Azubuso's method?
    Thnx

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  14. Offline

    rsod

    BlueMustache
    So 25565 for server, 35565 for map, huh?
     
  15. Offline

    BlueMustache

    rsod

    Not at all.
    I solved it anyway.
    "The computers were moving a little slow for me." - Captain America
    Here is what I used.

    Code:java
    1. public int getNewPort(int portinput) {
    2. String port = Integer.toString(portinput);
    3. char one = port.charAt(0);
    4. String character = Character.toString(one);
    5. String newport = "";
    6. newport = port.replaceAll(character, "");
    7. newport = newport + one;
    8. int portoutput = Integer.parseInt(newport);
    9. return portoutput;
    10. }


    Thanks anyway.
    Thread closed.
     
Thread Status:
Not open for further replies.

Share This Page