[Lib] ImageMessage (v2.1)- Send images to players via the chat!

Discussion in 'Resources' started by bobacadodl, Dec 10, 2013.

Thread Status:
Not open for further replies.
  1. bobacadodl
    Why do I get an error when I put portal.gif in the place of IMAGE and how does it know where to look for portal.gif?
     
  2. Offline

    Qwahchees

    Wow, this is really amazing!

    Good job!
     

  3. @bobacadodl
    Is it possible to use the animated messages for lores?
     
  4. Yes, it is. You just need to create a runnable which will update the lore in the item every few ticks by setting the lore to the next frame of the AnimatedMessage
     
  5. @bobacadodl
    I hope you can help me, I used this method to make my menus

    Code:java
    1. if (num == 1) {
    2. inv.setItem(12, createItem(Material.DIAMOND_SWORD, 1, (short) 0, "ItemName", "ItemLore"));

    This is to create the item in an inventory space, attach the name and lore

    Code:java
    1. public ItemStack createItem(Material material, int amount, short shrt, String displayname, String lore) {
    2. ItemStack i = new ItemStack(material, amount, (short) shrt);
    3. ItemMeta im = i.getItemMeta();
    4. im.setDisplayName(displayname);
    5.  
    6. ArrayList<String> loreList = new ArrayList<String>();
    7. String[] lores = lore.split("/");
    8. loreList.addAll(Arrays.asList(lores));
    9.  
    10. im.setLore(loreList);
    11. i.setItemMeta(im);
    12. return i;
    13. }

    And this is to add the description and to use my metode, I think this is what I have to change.
    My question is:
    I have to change or add to add a gif image as lore?

    @bobacadodl
    You can help me?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. You have to change the lore. If you add lore, that will just add more lines of the lore text..
     
  7. how?
     
  8. Youre already setting lore in your createItem method... I'm not sure what you're asking
     
  9. @bobacadodl
    Ok, I use this method to create menus, my question is, How can I add a picture ".gif" as lore for one item?, Could you show me an example code?
     
  10. I dont have time to type up an example right now, but this is how it would work..
    1. create the inventory object with Bukkit.createInventory();
    2. create a new AnimatedMessage object, that has the gif
    3. set an item into the inventory
    4. Start a new bukkitRunnable that keeps updating the item in the inventory object and setting its lore to the next frame of the AnimatedMessage
     
  11. @bobacadodl

    @Onlineids
    Ok, i make the Bukkit inventory and Runnable, but how do the AnimatedMessage object?, I leave the code
    Code:java
    1. public class Principal extends JavaPlugin implements Listener{
    2.  
    3. public void onEnable(){
    4. final Inventory inv;
    5. final int num = 1;
    6. getServer().getPluginManager().registerEvents(this,this);
    7.  
    8. inv = Bukkit.createInventory(null, 9, "<<Example>>");
    9.  
    10. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    11.  
    12. public void run() {
    13. if (num == 1) {
    14. inv.setItem(8, createItem(Material.NETHER_STAR, 1, (short) 0, "Example", "Example"));
    15.  
    16. }else if(num == 2){
    17. inv.setItem(8, createItem(Material.NETHER_STAR, 1, (short) 0, "Example", "Example"));
    18.  
    19. }
    20. }
    21.  
    22. }, 0, 1 * 4);
    23. }
    24. public ItemStack createItem(Material material, int amount, short shrt, String displayname, String lore) {
    25. ItemStack i = new ItemStack(material, amount, (short) shrt);
    26. ItemMeta im = i.getItemMeta();
    27. im.setDisplayName(displayname);
    28.  
    29. ArrayList<String> loreList = new ArrayList<String>();
    30. String[] lores = lore.split("/");
    31. loreList.addAll(Arrays.asList(lores));
    32.  
    33. im.setLore(loreList);
    34. i.setItemMeta(im);
    35. return i;
    36. }
    37. }
     
  12. To the people who are having issues at least where to put the image so it all works correctly you just drag and drop it. So as you can see his 3 files are located next to my main under my folder. And the img itself is at the bottom where you put your plugin.yml. Hope this helps those who are confused.
    [​IMG]
    So on eclipse you just drag the img file onto the Project

    and here's the static method that was on the github i used and it worked
    Code:java
    1. package com.paulreitz.mobmessagemain;
    2.  
    3. import java.awt.image.BufferedImage;
    4. import java.io.IOException;
    5.  
    6. import javax.imageio.ImageIO;
    7.  
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.player.PlayerJoinEvent;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. public class Mobmessagemain extends JavaPlugin implements Listener {
    18.  
    19.  
    20. public void onEnable()
    21. {
    22. getLogger().info("Mob Message Enabled");
    23. getServer().getPluginManager().registerEvents(this, this);
    24. }
    25. public void onDisable()
    26. {
    27.  
    28. }
    29. @EventHandler
    30. public void onJoin(PlayerJoinEvent event) throws IOException {
    31. BufferedImage imageToSend = ImageIO.read(this.getResource("creepermap.png"));
    32. new ImageMessage(
    33. imageToSend, // the bufferedimage to send
    34. 8, // the image height
    35. ImageChar.MEDIUM_SHADE.getChar() // the character that the image is made of
    36. ).appendText(
    37. "",
    38. "",
    39. "",
    40. "Thatssss a",
    41. "niccceee house",
    42. "you've got there"
    43. ).sendToPlayer(event.getPlayer());
    44. }
    45. }
    46.  
     
  13. Someone can help me?
    I really interested in learning
     
  14. Offline

    Coopah

    Yeah having errors, ImageMessage cannot be resolved as a type. Using the code above ^. The creepermap is in my project folder.
     
  15. Offline

    NewBreedGaming

    I'm having troubles implementing the animation of gif's, I can get the image to display correctly in the lore of an item, would you be able to give an example?

    Thanks very much for providing such a great api! :)
     
  16. bobacadodl
    Trying to use gifs, and getting this error.
    Code:
    26.04 07:57:14 [Server] INFO at com.rebelempiremc.sigler.RandomLore$1.run(RandomLore.java:57) ~[?:?]
    26.04 07:57:14 [Server] INFO java.lang.NullPointerException
    26.04 07:57:14 [Server] WARN Task #27 for RandomLore v1.0 generated an exception
    26.04 07:57:14 [Server] INFO at 
    Actual code:
    Code:java
    1. ItemMeta meta = item.getItemMeta();
    2. List<String> lore = new ArrayList<String>();
    3. String[] gif = message.next().getLines(); //Error is on this line.
    4. for (String loreadd : gif){
    5. lore.add(loreadd);
    6. }
    7. meta.setLore(lore);
    8. item.setItemMeta(meta);


    I have message defined as a global variable.
     
  17. This works great, the only problem is with converting player skins. Out of the 8 or so I've tried a good 3/4 of them are ruined because of gray or white when they clearly should be a different color.

    Examples:
    http://prntscr.com/3e3fk6 (In Game)
    http://prntscr.com/3e3fuq (How it actually is)

    I know its like this because of the limitations of the minecraft chat colors, so sadly theres probably no fix :(
     
  18. This is the greatest thing ever (Thanks, @bobacadodl !). time to combine Plo124 's IPUtil with this. Now... lets animate what happens when Jimmy doesn't get out of the house...


    A tornado is nearby
    uh oh.
    █ And fire o.o

    █ You should get out.

    Nao.
     
    stirante, Skyost and Plo124 like this.
  19. Offline

    ledship

    Can someone provide an example of code of how to set this as a lore of an item?
     
  20. Offline

    ledship

  21. Offline

    ledship

    Thanks.
     
  22. bobacadodl
    Hey there, this is an awesome library! I was wondering if I could use this in the next version of my plugin, Animated Menu(I will, of couse, credit you for this on the page).
     
  23. Offline

    TheLexoPlexx

    Is it also possible to simply return an ArrayList? To make the Images as a Lore of an Item?
     
  24. TheLexoPlexx
    Something like this?
    Code:java
    1. public List<String> getLines(File file) {
    2. BufferedImage image = null;
    3. try {
    4. image = ImageIO.read(new File(this.getDataFolder() + File.separator + file)); //or whatever location of the file
    5. } catch (IOException e) {
    6. e.printStackTrace();
    7. }
    8. ImageMessage message = new ImageMessage(image, image.getHeight(), ImageChar.BLOCK.getChar());
    9. return Arrays.asList(message.getLines());
    10. }
     
Thread Status:
Not open for further replies.

Share This Page