[Sothatsit's Useful Snippets] - Block Letters, MobBarAPI, AutoRespawn + More!

Discussion in 'Resources' started by SoThatsIt, Feb 1, 2014.

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

    SoThatsIt

    DHere are some useful snippets of code i have created or found to make life that little bit easier.

    UPlayer:By Sothatsit
    UPlayer.java
    Static Class to easily store data per player which can be accessed from anywhere, just add your own variables to the class as you need them. For example, you could add an score variable and then have 2 methods getScore() which returns the score and addScore(int score) to add to a players score.

    note: if you wish to save/load the players all variables you add to the class must be serializable. that means no Blocks, Locations, Worlds, Players, Entities and many others, if you get a notserializableexception then you know you have a variable in the class which isnt serializable.

    LogFile:By Sothatsit
    LogFile.java
    Just a simple log file handler with an auto save option and file headers.

    Letter:By Sothatsit
    Letter.java
    Direction.java
    I know, its probably a bit overcomplicated to type out each letter but i couldnt think of an alternative until codename b suggested i use one of the MinecraftFont class in bukkit. I could probably change it but this works well and probably has a tiny bit more performance because of it.

    This class can print out text in the sky using blocks.

    Note: you have to include both classes (Direction and Letter) in order to use this.

    EnchantGlow:By Sothatsit
    EnchantGlow.java
    Used to add a glow to an item without needing to edit its nbt data or give it an actual enchantment.

    ItemUtils:By Sothatsit
    ItemUtils.java
    Just a simple class to help with items, main thing is really the fromString method ;)

    Note: this class will throw errors if you do not have the enchantglow class as well, to fix the error just delete the addGlow() method or include the enchantglow class.

    MinecartEditor:By Sothatsit
    MinecartEditor.java
    Edit the blocks in minecarts and how high the blocks in the minecarts are.

    MobBarAPI:By Sothatsit
    MobBarApi.java
    Probably one of my favourite utils, use the mob bar to display text. Just use MobBarAPI.getInstance() and then the setStatus() method to set someones status.

    Selection:By Sothatsit
    Selection.java
    Just a simple class to handle selections and the restoration of blocks within them.

    AutoRespawn: By Sothatsit
    AutoRespawn.java
    A simple auto respawn class, just add it to your project and then just create it using "new AutoRespawn(this)" in your onEnable and players will be automatically respawned when they die! this is very useful for pvp minigames and servers.

    If you have any useful classes that you would like me to add to the post above just post them below along with a short description and i will add them.

    OmerrgUtils: By Ommerg
    OmerrgUtils.java
    A bunch of useful methods including:
    rainbowChatColor(String) - takes a string and makes each character have its own colour

    coloredArmour(Material, Color, String) - returns a coloured piece of armour with the specificied material, color and name.

    skullFromString(String player, String name) - returns a skull of the player specified and with the display name specified.

    getMidMessage(String message) - returns a version of the message where the message is centred in the middle of the screen

    ColourWave: By Sothatsit
    ColourWave.java
    Input a string and then add colours and use next method and the colours will scroll through the string.

    Example:
    input string -> "TheWalls"
    then you add the colour gold
    as you use the next() method
    "&6TheWalls" -> "T&6heWalls" -> "Th&6eWalls" -> "The&6Walls"
    It Supports more than 1 colour so you could add a different colour every 4 characters or even every character.

    SerializableStuff: By Sothatsit
    Serializable Classes
    Lots of different classes which you can use to save things which aren't usually serializable (save-able).
    includes:
    Locations
    Items
    Inventories(including players armour)
    Selections

    MultiMap: By Yonas
    MultiMap Classes
    A Map class similar to a HashMap although with 2 values instead of 1. This could be useful when you need to store a little bit more information than a hash map allows without you having to create a custom class to store 2 variables.

    AvilGUI: By ChaseChocolate
    AnvilGUI Thread
    Use the anvil GUI as an input alternative for Strings! Uses the text bar you use when renaming items for text input.

    ChestHandler: By Yonas
    ChestHandler Classes
    Makes handling chests easier. Can be very useful for mini games.

    InventoryFactor: By DarkBladee12
    InventoryFactory Class
    Easily serialize an inventory to and from a string

    Github:
    [​IMG]
    There are some more classes not listed here that are also useful in the github repository!

    hope you enjoy!
     
    DJSkepter, 000nick, codex01 and 25 others like this.
  2. Offline

    Flybelette

    You are awesome ! :p
     
    SoThatsIt likes this.
  3. Offline

    DrJava

    love it
     
    SoThatsIt likes this.
  4. Offline

    97WaterPolo

    Love you so much right now!
     
    stonebloodtv and SoThatsIt like this.
  5. Offline

    Scullyking

    Awesome stuff, thanks :D
     
    SoThatsIt likes this.
  6. Offline

    Desle

    Cool. Just one thing.. Is it not possible to add glow to a block that's not enchantable normally?
     
  7. Offline

    DrJava

    Yes, it is.
     
  8. Offline

    Desle

    DrJava
    didint work for me sadly, might post code tomorrow.
     
  9. Offline

    SoThatsIt

    im not sure of this one, would have to test it but i am too lazy :p

    Anyway, i added a new AutoRespawn class which i just made for a minigame im making and i fixed the selection class as it was broken.

    Edit: also, if anyone has any useful classes of their own post them here so everyone else can leach off of your brilliance :p
     
  10. Offline

    Omerrg

    Heyo, Its RG, just came to post some snippets from my util class in my plugin, may be useful for someone (sorry if its a bit messed, you can fix them as you want)
    Code:java
    1.  
    2. public static String rainbowChatColor(String string)
    3. {
    4. int lastColor = 0;
    5. int currColor = 0;
    6. String newMessage = "";
    7. String colors = "123456789abcde";
    8. for (int i = 0; i < string.length(); i++)
    9. {
    10. do
    11. {
    12. currColor = new Random().nextInt(colors.length() - 1) + 1;
    13. } while (currColor == lastColor);
    14.  
    15. newMessage += ChatColor.RESET.toString() + ChatColor.getByChar(colors.charAt(currColor)) + "" + string.charAt(i);
    16.  
    17. }
    18. return newMessage;
    19. }
    20. public static String getMidMessage(String s)
    21. {
    22. int le = (62 - s.length()) / 2;
    23. String newS = "";
    24. for (int i = 0; i < le; i++)
    25. {
    26. newS += ChatColor.GOLD + "*";
    27. }
    28. newS += s;
    29. for (int i = 0; i < le; i++)
    30. {
    31. newS += ChatColor.GOLD + "*";
    32. }
    33. return newS;
    34. }
    35. public static ItemStack coloredArmor(Material m, Color color, String name)
    36. {
    37. ItemStack leatherArmor = new ItemStack(m);
    38. LeatherArmorMeta meta = (LeatherArmorMeta) leatherArmor.getItemMeta();
    39. meta.setColor(color);
    40. if (name != null)
    41. {
    42. meta.setDisplayName(name);
    43. }
    44. leatherArmor.setItemMeta(meta);
    45. return leatherArmor;
    46. }
    47. public static ItemStack skullFromString(String s, String name)
    48. {
    49. ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
    50. SkullMeta meta = (SkullMeta) skull.getItemMeta();
    51. meta.setOwner(s);
    52. if (name != null)
    53. {
    54. meta.setDisplayName(name);
    55. }
    56. skull.setItemMeta(meta);
    57. return skull;
    58. }
    59.  

    i think the name explain the method, if not just quote me :) hope i helped. (Its really basic, just simple methods to help you)
     
    SoThatsIt likes this.
  11. Offline

    SoThatsIt

    Awesome! thanks for posting this, ill put it all into a class and upload it to the githubs :D

    although, could you explain what the getMidMessage() method does?
     
  12. Offline

    Omerrg

    Heyo, thx for adding my utils, I'll bring you some more when I get home. The getMidMessage method makes your input be centered in the chat window, kinda useful for me. Try it out and try to describe it.. XD anyways, please fix the name to : Omerrg .
    Have a nice day
     
  13. Offline

    SoThatsIt

    Woops, sorry fixed it
     
  14. Offline

    Yonas

    SoThatsIt likes this.
  15. Offline

    SoThatsIt

  16. Offline

    DrJava

    SoThatsIt
    You should add multi line support to the letter class;)
     
  17. Offline

    LegitJava

    Woah, awesome snippets dude! These will definitely help me out for development for future plugins! Thanks! :D
     
    SoThatsIt likes this.
  18. Offline

    SoThatsIt

    Added multi line support and a strHeight() method
     
  19. Offline

    chasechocolate

  20. Offline

    SoThatsIt

  21. Offline

    DrMedia

    I already posted something in his thread about your mobbarapi on my old account, but I think staff never accepted it:p
     
  22. Offline

    xTrollxDudex

    DrJava DrMedia
    WTF. Who is the legit Taylor King? Are you both the same person?
     
  23. Offline

    Yonas

    SoThatsIt likes this.
  24. Offline

    SoThatsIt

  25. Offline

    thepaperboy99

    Thanks for these! I'l be sure to use the Letter class for drawing words. Thanks again!
     
    SoThatsIt likes this.
  26. Offline

    jusjus112

    SoThatsIt
    I have the MobBarAPI, but in eclipse i have more then 50 red lines.
    Under the ReflectionUtils, but were can i find those?>
     
  27. Offline

    darkness1999

  28. Offline

    97WaterPolo

    How would you use the ColourWave? I don't see any methods defined in my IDE?
     
  29. Offline

    SoThatsIt

    just look at the source of colourwave, im sure you'll be able to figure it out
     
  30. Offline

    97WaterPolo

    SoThatsIt
    K, is there a way to clear the Boss Bar? Or set a time limit on it?
     
Thread Status:
Not open for further replies.

Share This Page