[class] monospace fixed width fonts

Discussion in 'Resources' started by atesin, Apr 20, 2014.

Thread Status:
Not open for further replies.
  1. hi all

    i am writing a teleportation plugin (MyPortals) ... in the meanwhile i had the need to list all teleports with its data

    then i realized minecraft chat window have variable width fonts and there is no way to print tabbed data .. so i wrote a class to do it

    i am not a java expert, writing costed me a lot of tests and brain heating, but i want to share it with you if you have the same need i had and want to use it .. and improve it of course, just let me know

    mc-mono.png

    mc-mono2.png

    mc-mono3.png

    VERSION 2: now has 2 methods for sort lines by field(s)
    VERSION 3: optimized code, better stability, improved methods
    VERSION 4: little bug fixes
    NEXT VERSIONS: bugfixes, new functions and optimizations

    now you can see the latest code at my github page:

    https://github.com/atesin/myportals/blob/master/MyPortals/src/cl/netgamer/tabtext/TabText.java
     
  2. atesin
    This is great looks really nice, But I think this would be more useful in the resources section of bukkit.

    I will see about using this is my work in the future (I will give you credit of course)

    --Heirteir
     
  3. I suggest putting it in a github gist where the formatting won't break.
     
  4. Moved to a more appropriate section.
     
    Garris0n likes this.
  5. Jade, you killed this post by moving, but is ok

    i wish everybody use this class, and contribute to enhance it if you can
     
  6. Had no idea what it was until you added pictures. I'll probably use this soon!
     
  7. I think im going to use this... will let you know how it works!

    Hey, can you give us an example on how to use this? I see in the code "Usage", but can you give an example on some sample code, sample columns / tabs, and pages?

    Thanks!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  8. see the 1st screenshot? .... suppose you have a portals plugin (like the one i am writing :) ) .. and your portals have the properties

    - portal location
    - portal name
    - destination portal name
    - owner player

    and you have a command "/portals list" or something ...then you need to iterate all portals and build a multiline string "mLString" like

    W-3138+61-471`casaAtesin4`subLaberinto`ATESIN
    W-891+60-278`casaAzsrul2`null`ATESIN
    W-2746+72-497`puebloLejano`null`ATESIN
    W-2489+13-487`fosaProfunda`null`ATESIN
    W-3259+13-386`subLaberinto`null`ATESIN
    W-3131+69-488`null`<NOT`SET>`ATESIN
    W+5285+68-713`null`<NOT`SET>`RATULCO
    W+4626+38+529`null`<NOT`SET>`RATULCO
    W+2191+62+756`AldeaAgua2`Aldea001`RATULCO
    W+5734+63-787`PlanicieCaba`<NOT`SET>`RATULCO
    W+5364+73+157`FortalezaPla`<NOT`SET>`RATULCO
    W+5927+64+29`Aldea001`AldeaAgua2`RATULCO

    then you can create a TabText with this and get tabbed columns
    Code:
    TabText tt = new TabText(mLString);
    player.sendMessage(tt.getPage(1));
    and the result you already know it

    [​IMG]

    internals: the new TabText object holds and manages the multiline text passed, you can query how many pages they have, and when you request some page it "count" the font pixels and fill it with spaces until finds a field separator

    stay tuned because soon i think to upload a newer version

    .
     
  9. in response to Sleepydragn1 at http://forums.bukkit.org/threads/text-alignment-in-chat.83895/#post-2502117

    i found the problem !!

    i thought default behavior was consider variable width fonts, but it was monospace fonts ... you have 2 fixes for this, change default behavior or explicitly said everytime you are using variable width fonts, if you send this command raw from console it gets perfectly aligned

    - to change default behavior (recommended) edit line 50 to look "public boolean monospace = false;" (no quotes)
    - to be explicit, call getPage() with the monospace parameter: "sender.sendMessage(tt.getPage(1, false));" (no quotes)

    your plugin should detect if you are sending your command from console or from minecraft chat, and use "monospace" parameter properly
     
  10. hi

    i uploaded version 3 and i feel very satisfied with it

    [​IMG]

    see details in starting post .. i pasted full class code too
     
Thread Status:
Not open for further replies.

Share This Page