Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.md_5.bungee.BungeeCord;
import ru.leymooo.botfilter.caching.CachedCaptcha;
import ru.leymooo.botfilter.caching.PacketUtils;
import ru.leymooo.botfilter.captcha.generator.CaptchaPainter;
import ru.leymooo.botfilter.captcha.generator.map.MapPalette;
import ru.leymooo.botfilter.config.Settings;

Expand Down Expand Up @@ -55,7 +54,6 @@ private static void generateCaptchas()
.setPriority( Thread.MIN_PRIORITY )
.setNameFormat( "CaptchaGenerationTask-thread-%d" )
.build() );
CaptchaPainter painter = new CaptchaPainter();
MapPalette.prepareColors();

int captchaCount = Settings.IMP.CAPTCHA.COUNT;
Expand All @@ -69,7 +67,7 @@ private static void generateCaptchas()

for ( int i = 1; i <= captchaCount; i++ )
{
executor.execute( new CaptchaGenerationTask( executor, painter, fonts, holders ) );
executor.execute( new CaptchaGenerationTask( executor, fonts, holders ) );
}

long start = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public class CaptchaGenerationTask implements Runnable
{
private final ExecutorService executor;
private final CaptchaPainter painter;
private final List<Font> fonts;
private final List<CachedCaptcha.CaptchaHolder> holders;
@Override
Expand All @@ -30,7 +29,8 @@ public void run()
{
Random rnd = ThreadLocalRandom.current();
String answer = randomAnswer( rnd );
BufferedImage image = this.painter.draw( this.fonts.get( rnd.nextInt( this.fonts.size() ) ), randomNotWhiteColor( rnd ), answer );
CaptchaPainter painter = new CaptchaPainter( rnd );
BufferedImage image = painter.draw( this.fonts.get( rnd.nextInt( this.fonts.size() ) ), randomNotWhiteColor( rnd ), answer );
final CraftMapCanvas map = new CraftMapCanvas();
map.drawImage( 0, 0, image );
MapDataPacket packet = new MapDataPacket( 0, (byte) 0, map.getMapData() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.util.Random;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class CaptchaPainter
{

private final int width = 128;
private final int height = 128;
private final Color background = Color.WHITE;
private final Random rnd = new Random();
private final Random rnd;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will just throw NPE's, please fix it!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will just throw NPE's, please fix it!

The class is annotated lombok with @requiredargsconstructor annotation
It generates a constructor where there is Random

New CaptchaPainter instances are created in the CaptchaGenerationTask class always with Random instances inside


public BufferedImage draw(Font font, Color fGround, String text)
{
Expand Down