EffectLib ColoredImageEffect not working!

Discussion in 'Plugin Development' started by maxben34, Nov 24, 2014.

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

    maxben34

    I am trying to use the ColoredImageEffect effect in EffectLib but I've found that although it can read my image and the black and white version works, the colored image version seems to not be working. I know my image is of the correct file type and is in the plugins folder.

    Slikey LCastr0


    Code:java
    1. /**
    2. * Particle to draw the image
    3. */
    4. public ParticleEffect particle = ParticleEffect.FLAME;
    5.  
    6. /**
    7. * Invert the image
    8. */
    9. public boolean invert = false;
    10.  
    11. /**
    12. * Each stepX pixel will be shown. Saves packets for high resolutions.
    13. */
    14. public int stepX = 10;
    15.  
    16. /**
    17. * Each stepY pixel will be shown. Saves packets for high resolutions.
    18. */
    19. public int stepY = 10;
    20.  
    21. /**
    22. * Scale the image down
    23. */
    24. public float size = (float) 1 / 40;
    25.  
    26. /**
    27. * Should it rotate?
    28. */
    29. public boolean enableRotation = true;
    30.  
    31. /**
    32. * What plane should it rotate?
    33. */
    34. public Plane plane = Plane.XYZ;
    35.  
    36. /**
    37. * Turns the cube by this angle each iteration around the x-axis
    38. */
    39. public double angularVelocityX = Math.PI / 200;
    40.  
    41. /**
    42. * Turns the cube by this angle each iteration around the y-axis
    43. */
    44. public double angularVelocityY = Math.PI / 170;
    45.  
    46. /**
    47. * Turns the cube by this angle each iteration around the z-axis
    48. */
    49. public double angularVelocityZ = Math.PI / 155;
    50.  
    51. /**
    52. * Image as BufferedImage
    53. */
    54. protected BufferedImage image = null;
    55.  
    56. /**
    57. * Is this a gif image?
    58. */
    59. protected boolean isGif = false;
    60.  
    61. /**
    62. * File of the gif if needed
    63. */
    64. protected File gifFile = null;
    65.  
    66. /**
    67. * Step counter
    68. */
    69. protected int step = 0;
    70.  
    71. public ImageEffect(EffectManager effectManager) throws IOException {
    72. super(effectManager);
    73. type = EffectType.REPEATING;
    74. period = 10;
    75. iterations = 10;
    76. }
    77.  
    78. public void loadFile(File file) {
    79. try {
    80. image = ImageIO.read(file);
    81. this.isGif = file.getName().endsWith(".gif");
    82. this.gifFile = file;
    83. } catch (Exception ex) {
    84. ex.printStackTrace();
    85. image = null;
    86. }
    87. }
    88.  
    89. @Override
    90. public void onRun() {
    91. if (image == null) {
    92. cancel();
    93. return;
    94. }
    95. if(isGif){
    96. try {
    97. image = getImg(step);
    98. } catch (IOException e) {
    99. e.printStackTrace();
    100. }
    101. step++;
    102. }
    103. Location location = getLocation();
    104. int clr;
    105. for (int y = 0; y < image.getHeight(); y += stepY) {
    106. for (int x = 0; x < image.getWidth(); x += stepX) {
    107. clr = image.getRGB(x, y);
    108. if (!invert && Color.black.getRGB() != clr)
    109. continue;
    110. else if (invert && Color.black.getRGB() == clr)
    111. continue;
    112. Vector v = new Vector((float) image.getWidth() / 2 - x, (float) image.getHeight() / 2 - y, 0).multiply(size);
    113. VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians);
    114. particle.display(location.add(v), visibleRange);
    115. location.subtract(v);
    116. }
    117. }
    118. }
    119.  
    120. private BufferedImage getImg(int s) throws IOException{
    121. ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
    122. ImageReader reader = ImageIO.getImageReadersBySuffix("GIF").next();
    123. ImageInputStream in = ImageIO.createImageInputStream(gifFile);
    124. reader.setInput(in);
    125. for (int i = 0, count = reader.getNumImages(true); i < count; i++){
    126. BufferedImage image = reader.read(i);
    127. images.add(image);
    128. }
    129. if(step>=reader.getNumImages(true)) {
    130. step = 0;
    131. return images.get(s-1);
    132. }
    133. return images.get(s);
    134. }
    135.  
    136. public enum Plane{
    137. X, Y, Z, XY, XZ, XYZ, YZ;
    138. }
     
  2. Offline

    LCastr0

    It just shows the class of the Colored Image...
    You have to do the same that you did to call the normal image.
    Can you show me how you're running it? I mean, all of your classes that contains anything related to it? Main class, commands or listeners...
     
  3. Offline

    maxben34

    I'm sorry I didn't include this lol hope this helps LCastr0

    Code:java
    1. ImageEffect effect = null;
    2. try {
    3. effect = new ImageEffect(new EffectManager(Main.plugin));
    4. } catch (IOException e) {
    5. // TODO Auto-generated catch block
    6. e.printStackTrace();
    7. return true;
    8. }
    9. File file = new File(Main.plugin.getDataFolder(), "Cookie.png");
    10. effect.loadFile(file);
    11. effect.setLocation(p.getLocation());
    12. effect.start();
     
  4. Offline

    LCastr0

    This is how I spawn, try this way too, please.
    Also, can you post here the image that you're trying to play and if there is any particle being spawned, a print of it?
    Code:
    try {
                            ColoredImageEffect coloredImageEffect = new ColoredImageEffect(plugin.manager);
                            coloredImageEffect.setLocation(player.getLocation());
                            coloredImageEffect.loadFile(new File("plugins/EffectLibTest/gifimage.gif"));
                            coloredImageEffect.iterations = 200;
                            coloredImageEffect.start();
                        } catch (IOException e) {
                            player.sendMessage(ChatColor.RED + "The image was not loaded! Make sure you have " +
                                    "an image called gifimage.gif in your /plugins/EffectLibTest/ folder!");
                            e.printStackTrace();
                        }
     
Thread Status:
Not open for further replies.

Share This Page