diff --git a/src/main/java/me/savvy/rixa/Rixa.java b/src/main/java/me/savvy/rixa/Rixa.java index 897818a..546df74 100644 --- a/src/main/java/me/savvy/rixa/Rixa.java +++ b/src/main/java/me/savvy/rixa/Rixa.java @@ -13,6 +13,7 @@ import me.savvy.rixa.commands.mod.DeleteMessagesCommand; import me.savvy.rixa.commands.mod.MuteCommand; import me.savvy.rixa.commands.mod.PurgeMessagesCommand; import me.savvy.rixa.commands.mod.RaidModeCommand; +import me.savvy.rixa.commands.owner.CleanGuildCommand; import me.savvy.rixa.commands.owner.OwnerCommand; import me.savvy.rixa.data.database.sql.SQLBuilder; import me.savvy.rixa.data.database.sql.other.DatabaseTables; @@ -92,10 +93,10 @@ public class Rixa { config.getJsonObject().getJSONObject("sql").getString("databaseName"), config.getJsonObject().getJSONObject("sql").getString("hostName")); Arrays.stream(DatabaseTables.values()).forEach(databaseTables -> { - getInstance().getLogger().info("Checking database table (creating if needed): " + databaseTables.toString()); + System.out.println("Checking database table (creating if needed): " + databaseTables.toString()); try { database.executeUpdate(databaseTables.getQuery()); - getInstance().getLogger().info("Done checking " + databaseTables.toString()); + System.out.println("Done checking " + databaseTables.toString()); } catch (SQLException e) { getInstance().getLogger().severe("Could not create table: " + databaseTables.toString()); e.printStackTrace(); @@ -137,7 +138,8 @@ public class Rixa { new ConfigCommand(), new UrbanDictionaryCommand(), new YoutubeCommand(), new AddRoleCommand(), new RemoveRoleCommand(), new LevelsCommand(), new LeaderboardCommand(), new RaidModeCommand(), new OwnerCommand(), - new ColorCommand(), new ModulesCommand()); + new ColorCommand(), new ModulesCommand(), new FeaturesCommand(), + new CleanGuildCommand()); register(new HelpReaction(), new ConfigReaction(), new LeaderboardReaction()); } diff --git a/src/main/java/me/savvy/rixa/commands/admin/AddRoleCommand.java b/src/main/java/me/savvy/rixa/commands/admin/AddRoleCommand.java index 5add63d..fb19843 100644 --- a/src/main/java/me/savvy/rixa/commands/admin/AddRoleCommand.java +++ b/src/main/java/me/savvy/rixa/commands/admin/AddRoleCommand.java @@ -42,9 +42,9 @@ public class AddRoleCommand implements CommandExec { return; } try { - int users = event.getMessage().getMentionedUsers().size(); + int users = memberList.size(); memberList.forEach(user -> event.getGuild().getController().addRolesToMember(user, roleList).queue()); - new MessageBuilder("Successfully given " + users + " `" + roleList.size() + "` role(s)").setColor(event.getMember().getColor()).queue(event.getChannel()); + new MessageBuilder("Successfully given " + users + " users `" + roleList.size() + "` role(s)").setColor(event.getMember().getColor()).queue(event.getChannel()); } catch (PermissionException ex) { new MessageBuilder(event.getMember().getAsMention() + ", sorry I do not have permission for this!").setColor(event.getMember().getColor()).queue(event.getChannel()); } diff --git a/src/main/java/me/savvy/rixa/commands/admin/RemoveRoleCommand.java b/src/main/java/me/savvy/rixa/commands/admin/RemoveRoleCommand.java index 3924558..9d035a2 100644 --- a/src/main/java/me/savvy/rixa/commands/admin/RemoveRoleCommand.java +++ b/src/main/java/me/savvy/rixa/commands/admin/RemoveRoleCommand.java @@ -42,7 +42,7 @@ public class RemoveRoleCommand implements CommandExec { return; } try { - int users = event.getMessage().getMentionedUsers().size(); + int users = memberList.size(); memberList.forEach(user -> event.getGuild().getController().removeRolesFromMember(user, roleList).queue()); new MessageBuilder("Successfully removed `" + roleList.size() + "` role(s) from " + users + " user(s)!").setColor(event.getMember().getColor()).queue(event.getChannel()); } catch (PermissionException ex) { diff --git a/src/main/java/me/savvy/rixa/commands/general/FeaturesCommand.java b/src/main/java/me/savvy/rixa/commands/general/FeaturesCommand.java index 9996e51..83e54b1 100644 --- a/src/main/java/me/savvy/rixa/commands/general/FeaturesCommand.java +++ b/src/main/java/me/savvy/rixa/commands/general/FeaturesCommand.java @@ -16,10 +16,14 @@ public class FeaturesCommand implements CommandExec { @Override @Command(mainCommand = "features", description = "List Rixa Features!", + aliases = {"feature"}, channelType = ChannelType.TEXT) public void execute(GuildMessageReceivedEvent event) { RixaGuild rixaGuild = Guilds.getGuild(event.getGuild()); - String[] features = {}; + String[] features = { + "Music", "Economy", "Moderation", "Server List", "User Profiles", + "Role Management", "Fun Commands", "Custom Commands", "Games", "& more." + }; new MessageBuilder( features.length == 0 ? "There are currently no features listed." : "Rixa Features: " + String.join("\n", features diff --git a/src/main/java/me/savvy/rixa/commands/general/LevelsCommand.java b/src/main/java/me/savvy/rixa/commands/general/LevelsCommand.java index 1b3a776..0ae371e 100644 --- a/src/main/java/me/savvy/rixa/commands/general/LevelsCommand.java +++ b/src/main/java/me/savvy/rixa/commands/general/LevelsCommand.java @@ -33,13 +33,14 @@ public class LevelsCommand implements CommandExec { new MessageBuilder("Levels are not enabled on this server!").setColor(event.getMember().getColor()).queue(event.getChannel()); return; } + + List memberList = Utils.memberSearch(event.getGuild(), event.getMessage().getContent(), false); if (event.getMessage().getContent().split(" ").length == 2) { - if(event.getMessage().getMentionedUsers().size() < 1) { + if (memberList.size() < 1) { new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + rixaGuild.getGuildSettings().getPrefix() + "rank ].").setColor(event.getMember().getColor()).queue(event.getChannel()); return; } - List memberList = Utils.memberSearch(event.getGuild(), event.getMessage().getContent(), false); if (memberList.get(0) == null) { new MessageBuilder(event.getMember().getAsMention() + ", couldn't find user.").setColor(event.getMember().getColor()).queue(event.getChannel()); return; diff --git a/src/main/java/me/savvy/rixa/commands/general/ModulesCommand.java b/src/main/java/me/savvy/rixa/commands/general/ModulesCommand.java index f626eac..4735384 100644 --- a/src/main/java/me/savvy/rixa/commands/general/ModulesCommand.java +++ b/src/main/java/me/savvy/rixa/commands/general/ModulesCommand.java @@ -16,9 +16,10 @@ public class ModulesCommand implements CommandExec { @Override @Command(mainCommand = "modules", description = "List Rixa Modules!", + aliases = {"module"}, channelType = ChannelType.TEXT) public void execute(GuildMessageReceivedEvent event) { RixaGuild rixaGuild = Guilds.getGuild(event.getGuild()); - new MessageBuilder("Available Rixa Modules: " + String.join(",", rixaGuild.getModules().keySet())).setColor(event.getMember().getColor()).complete(event.getChannel()); + new MessageBuilder("Available Rixa Modules: " + String.join(", ", rixaGuild.getModules().keySet())).setColor(event.getMember().getColor()).complete(event.getChannel()); } } diff --git a/src/main/java/me/savvy/rixa/commands/general/MusicCommand.java b/src/main/java/me/savvy/rixa/commands/general/MusicCommand.java index e01333f..2a929ed 100644 --- a/src/main/java/me/savvy/rixa/commands/general/MusicCommand.java +++ b/src/main/java/me/savvy/rixa/commands/general/MusicCommand.java @@ -102,7 +102,9 @@ public class MusicCommand implements CommandExec { return; } try { - guild.getAudioManager().openAudioConnection(event.getMember().getVoiceState().getChannel()); + VoiceChannel channel = event.getMember().getVoiceState().getChannel(); + guild.getAudioManager().openAudioConnection(channel); + new MessageBuilder("Entering Voice Channel: " + channel.getName()).setColor(event.getMember().getColor()).queue(event.getChannel()); } catch (PermissionException e) { if (e.getPermission() == Permission.VOICE_CONNECT) { new MessageBuilder("I do not have permission to join the requested voice channel.").setColor(event.getMember().getColor()).queue(event.getChannel()); diff --git a/src/main/java/me/savvy/rixa/commands/owner/CleanGuildCommand.java b/src/main/java/me/savvy/rixa/commands/owner/CleanGuildCommand.java index 8b0f556..440ee02 100644 --- a/src/main/java/me/savvy/rixa/commands/owner/CleanGuildCommand.java +++ b/src/main/java/me/savvy/rixa/commands/owner/CleanGuildCommand.java @@ -3,17 +3,19 @@ package me.savvy.rixa.commands.owner; import me.savvy.rixa.commands.handlers.Command; import me.savvy.rixa.commands.handlers.CommandExec; import me.savvy.rixa.commands.handlers.CommandType; +import me.savvy.rixa.guild.user.profile.Profile; import me.savvy.rixa.utils.MessageBuilder; import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; +import java.io.IOException; + public class CleanGuildCommand implements CommandExec { @Override - @Command(mainCommand = "cleanguilds", - description = "Clean Inactive Guilds From Rixa's Database!", + @Command(mainCommand = "profile", + description = "Profile", channelType = ChannelType.TEXT, - showInHelp = false, type = CommandType.BOT_OWNER) public void execute(GuildMessageReceivedEvent event) { if (!event.getAuthor().getId().equalsIgnoreCase("202944101333729280")) { @@ -21,51 +23,10 @@ public class CleanGuildCommand implements CommandExec { .setColor(event.getMember().getColor()).queue(event.getChannel()); return; } - new MessageBuilder("Cleaning...").setColor(event.getMember().getColor()).queue(event.getChannel()); - int cleaned = 0; - /* DatabaseManager dbManager = Rixa.getDbManager(); - ResultSet rs = dbManager.executeQuery("SELECT * FROM `core`;"); try { - while (rs.next()) { - if (event.getJDA().getGuildById(rs.getString("guild_id")) == null) { - cleaned++; - String id = rs.getString("guild_id"); - //`core`, `levels`, `settings`, `music`, `modules`, `permissions` - if (checkExists("core", id)) - dbManager.executeUpdate("DELETE FROM `core` WHERE `guild_id` = " + id); - - if (checkExists("levels", id)) - dbManager.executeUpdate("DELETE FROM `levels` WHERE `guild_id` = " + id); - - if (checkExists("settings", id)) - dbManager.executeUpdate("DELETE FROM `settings` WHERE `guild_id` = " + id); - - if (checkExists("music", id)) - dbManager.executeUpdate("DELETE FROM `music` WHERE `guild_id` = " + id); - - if (checkExists("modules", id)) - dbManager.executeUpdate("DELETE FROM `modules` WHERE `guild_id` = " + id); - - if (checkExists("permissions", id)) - dbManager.executeUpdate("DELETE FROM `permissions` WHERE `guild_id` = " + id); - } - } - rs.getStatement().close(); - rs.close();*/ - new MessageBuilder(event.getAuthor().getAsMention() + ", successfully cleaned " + cleaned + " guilds from the database").setColor(event.getMember().getColor()).queue(event.getChannel()); - /*} catch (SQLException e) { - e.printStackTrace(); - }*/ - } - - private boolean checkExists(String table, String guildId) { - /*Result r = Result.ERROR; - try { - r = Rixa.getDbManager().checkExists("SELECT `" + guildId + "` FROM `" + table + "` WHERE `guild_id` = '" + guildId + "';"); - } catch (SQLException e) { + event.getChannel().sendFile(Profile.getInstance().get(event.getMember()), null).queue(); + } catch (IOException e) { e.printStackTrace(); } - return r == Result.TRUE;*/ - return true; } } diff --git a/src/main/java/me/savvy/rixa/data/database/sql/other/DatabaseTables.java b/src/main/java/me/savvy/rixa/data/database/sql/other/DatabaseTables.java index f04dae8..a25c047 100644 --- a/src/main/java/me/savvy/rixa/data/database/sql/other/DatabaseTables.java +++ b/src/main/java/me/savvy/rixa/data/database/sql/other/DatabaseTables.java @@ -21,7 +21,7 @@ public enum DatabaseTables { PERMISSIONS("CREATE TABLE IF NOT EXISTS `permissions` ( `role_id` varchar(255) NOT NULL, `guild_id` varchar(255) NOT NULL, `MUTE` tinyint(1) NOT NULL DEFAULT '0'," + " `ADD_ROLE` tinyint(1) NOT NULL DEFAULT '0', `REMOVE_ROLE` tinyint(1) NOT NULL DEFAULT '0', `CLEAR_CHAT` tinyint(1) NOT NULL DEFAULT '0'," + " `ACCESS_CONFIG` tinyint(1) NOT NULL DEFAULT '0', `PM_MESSAGE` tinyint(1) NOT NULL DEFAULT '0', `KICK_MEMBER` tinyint(1) NOT NULL DEFAULT '0'," + - " `BAN_MEMBER` tinyint(1) NOT NULL DEFAULT '0', `TOGGLE_RAIDMODE` tinyint(4) NOT NULL DEFAULT '0, `UNMUTE` tinyint(1) NOT NULL DEFAULT '0');"), + " `BAN_MEMBER` tinyint(1) NOT NULL DEFAULT '0', `TOGGLE_RAIDMODE` tinyint(4) NOT NULL DEFAULT '0', `UNMUTE` tinyint(1) NOT NULL DEFAULT '0');"), POLLS("CREATE TABLE IF NOT EXISTS `polls` ( `id` int(9) NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) NOT NULL, `description` text," + " `option_1` varchar(255) DEFAULT NULL, `option_2` varchar(255) DEFAULT NULL, `option_3` varchar(255) DEFAULT NULL," + diff --git a/src/main/java/me/savvy/rixa/events/MessageEvent.java b/src/main/java/me/savvy/rixa/events/MessageEvent.java index 3eb7dc2..a77dfed 100644 --- a/src/main/java/me/savvy/rixa/events/MessageEvent.java +++ b/src/main/java/me/savvy/rixa/events/MessageEvent.java @@ -24,7 +24,6 @@ import net.dv8tion.jda.core.hooks.SubscribeEvent; import java.awt.*; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.regex.Matcher; @@ -194,22 +193,26 @@ public class MessageEvent { @SubscribeEvent public void onGuildReact(GuildMessageReactionAddEvent event) { - if (event.getGuild() == null) return; - if (event.getUser().isBot()) return; - Message message = event.getChannel().getMessageById(event.getMessageId()).complete(); - if (message == null || message.getEmbeds().size() != 1) return; - MessageEmbed embed = message.getEmbeds().get(0); - if (StringUtils.isNullOrEmpty(embed.getTitle())) return; - String[] titleSplit = embed.getTitle().split(": "); - System.out.println(Arrays.toString(titleSplit)); - if (ReactionManager.getReactions().containsKey(titleSplit[0])) { - ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]); - Method m = reactRegistrar.getMethod(); - try { - m.invoke(reactRegistrar.getExecutor(), event); - } catch (Exception e) { - e.printStackTrace(); + try { + if (event.getGuild() == null) return; + if (event.getUser().isBot()) return; + Message message = event.getChannel().getMessageById(event.getMessageId()).complete(); + if (message == null || message.getEmbeds().size() != 1) return; + MessageEmbed embed = message.getEmbeds().get(0); + if (StringUtils.isNullOrEmpty(embed.getTitle())) return; + String[] titleSplit = embed.getTitle().split(": "); + if (ReactionManager.getReactions().containsKey(titleSplit[0])) { + ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]); + Method m = reactRegistrar.getMethod(); + try { + m.invoke(reactRegistrar.getExecutor(), event); + } catch (Exception e) { + e.printStackTrace(); + } } + } catch (PermissionException pex) { + if (pex.getPermission() == Permission.MESSAGE_READ) return; + pex.printStackTrace(); } } } \ No newline at end of file diff --git a/src/main/java/me/savvy/rixa/guild/user/profile/Profile.java b/src/main/java/me/savvy/rixa/guild/user/profile/Profile.java new file mode 100644 index 0000000..bb21383 --- /dev/null +++ b/src/main/java/me/savvy/rixa/guild/user/profile/Profile.java @@ -0,0 +1,184 @@ +package me.savvy.rixa.guild.user.profile; + +import me.savvy.rixa.guild.RixaGuild; +import me.savvy.rixa.guild.management.Guilds; +import me.savvy.rixa.guild.user.UserData; +import me.savvy.rixa.modules.levels.LevelsModule; +import net.dv8tion.jda.core.entities.Member; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.geom.Ellipse2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Locale; +import java.util.Random; +import java.util.StringTokenizer; +import java.util.concurrent.ThreadLocalRandom; + +public class Profile { + + String mainPath; + private static Profile instance; + private File mainProfile; + public Profile() { + instance = this; + mainPath = "Rixa/profile/"; + mainProfile = new File(mainPath + "profile.png"); + } + + /* + This method draws final image. + */ + public File get(Member member) throws IOException { + if (member == null || member.getGuild() == null) return null; + RixaGuild rixaGuild = Guilds.getGuild(member.getGuild()); + LevelsModule levelsModule = (LevelsModule) rixaGuild.getModule("Levels"); + UserData userData = levelsModule.getUserData(member.getUser().getId()); + BufferedImage img = ImageIO.read(mainProfile); + + Graphics2D graphics2D = (Graphics2D) img.getGraphics(); + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 75)); + + // Profile Pic + graphics2D.drawImage( + ImageIO.read( + refactorImage(new URL(member.getUser().getAvatarUrl()) + , new File(mainPath + "profileImg.png") + ) + ), 50, 43, null); + + // All things related to userName + String name = member.getEffectiveName(); + // 900 is pretty much the beginning for 10 string chars + int x = 1075; + if (name.length() > 10 && name.length() < 20) { + x = 1180; + } else if (name.length() > 20) { + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 50)); + name = name.substring(0, 17) + "..."; + //x = 1180; + } + x = x - graphics2D.getFontMetrics().stringWidth(name); + graphics2D.drawString(name, x, 182); + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 50)); + Random r = ThreadLocalRandom.current(); + + // Premium / Regular User + graphics2D.drawString(r.nextBoolean() ? "Premium User" : "Regular User", 725, 245); + + // Exp Bar + graphics2D.setFont(new Font("Lato Light", Font.PLAIN, 50)); + graphics2D.drawString(userData.getRemainingExperience() + "/" + userData.getNeededXP + (userData.getLevelFromExperience(userData.getExperience())).intValue(), 660, 345); + + // User Level + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 75)); + graphics2D.drawString(String.valueOf(userData.getLevel()), 1280, 355); + + // Statistic Names + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 50)); + graphics2D.drawString("Total Experience", 330, 450); + graphics2D.drawString("Global Rank", 330, 550); + graphics2D.drawString("Tokens", 330, 650); + + // Statistic Values + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + graphics2D.drawString(numberFormat.format(userData.getExperience()), 1140, 450); + graphics2D.drawString("#" + userData.getLevel(), 1240, 550); + graphics2D.drawString("WIP", 1170, 650); + + + // Quote + graphics2D.setFont(new Font("Lato Light", Font.PLAIN, 30)); + java.util.List list = addLinebreaks("How far you go in life depends on you being tender with the young, compassionate with the aged, " + + "sympathetic with the striving and tolerant of the weak and the strong. Because someday in life you will have been all of these.", 60); + int i = 750; + StringBuilder b = new StringBuilder(); + for (String string : list ) { + if (string.equalsIgnoreCase(":newLine:")) { + graphics2D.drawString(b.toString().trim(), 330, i); + i += 40; + b = new StringBuilder(); + continue; + } + b.append(string); + } + + // Quote Author + graphics2D.setFont(new Font("Lato Light", Font.PLAIN, 25)); + graphics2D.drawString("- George Washington Carver",330, 900); + + // Badges + BufferedImage badgeOne = ImageIO.read(new File(mainPath + "badges/patreon.png")); + graphics2D.drawImage(badgeOne, 1231, 924, 61, 71, null); + + BufferedImage badgeTwo = ImageIO.read(new File(mainPath + "badges/contributor-staff.png")); + graphics2D.drawImage(badgeTwo, 981, 922, 61, 71, null); + + BufferedImage badgeThree = ImageIO.read(new File(mainPath + "badges/contributor-user.png")); // correct + graphics2D.drawImage(badgeThree, 1105, 922, 61, 71, null); + + File outputfile = new File(mainPath + "finalImage.png"); + ImageIO.write(img, "png", outputfile); + return outputfile; + } + + + private File refactorImage(URL input, File outputFile) throws IOException { + final HttpURLConnection connection = (HttpURLConnection) input.openConnection(); + connection.setRequestProperty( + "User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31"); + BufferedImage img = ImageIO.read(connection.getInputStream()); + int width = img.getWidth(); + BufferedImage circleBuffer = new BufferedImage(width, width, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = circleBuffer.createGraphics(); + g2.setClip(new Ellipse2D.Float(0, 0, width, width)); + g2.drawImage(img, 0, 0, width, width, null); + circleBuffer = resize(circleBuffer, 340, 340); + ImageIO.write(circleBuffer,"png", outputFile); + return outputFile; + } + + /** + * This method resizes + * @param img + * @param newW + * @param newH + * @return + */ + private BufferedImage resize(BufferedImage img, int newW, int newH) { + Image tmp = img.getScaledInstance(newW, newH, Image.SCALE_SMOOTH); + BufferedImage dimg = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = dimg.createGraphics(); + g2d.drawImage(tmp, 0, 0, null); + g2d.dispose(); + return dimg; + } + + private java.util.List addLinebreaks(String input, int maxLineLength) { + StringTokenizer tok = new StringTokenizer(input, " "); + java.util.List list = new ArrayList<>(); + // StringBuilder output = new StringBuilder(input.length()); + int lineLen = 0; + while (tok.hasMoreTokens()) { + String word = tok.nextToken(); + if (lineLen + word.length() > maxLineLength) { + list.add(":newLine:"); + lineLen = 0; + } + list.add(word + " "); + lineLen += word.length(); + } + return list; + } + + public static Profile getInstance() { + return (instance == null) ? new Profile() : instance; + } +} diff --git a/src/main/java/me/savvy/rixa/modules/economy/EconomyModule.java b/src/main/java/me/savvy/rixa/modules/economy/EconomyModule.java new file mode 100644 index 0000000..1e21007 --- /dev/null +++ b/src/main/java/me/savvy/rixa/modules/economy/EconomyModule.java @@ -0,0 +1,32 @@ +package me.savvy.rixa.modules.economy; + +import lombok.Getter; +import lombok.Setter; +import me.savvy.rixa.modules.RixaModule; + +public class EconomyModule implements RixaModule { + + @Getter + @Setter + private boolean enabled; + + @Override + public String getName() { + return "Economy"; + } + + @Override + public String getDescription() { + return null; + } + + @Override + public void load() { + + } + + @Override + public void save() { + + } +} diff --git a/src/main/java/test/Test.java b/src/main/java/test/Test.java new file mode 100644 index 0000000..8384f0b --- /dev/null +++ b/src/main/java/test/Test.java @@ -0,0 +1,171 @@ +package test; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.geom.Ellipse2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Random; +import java.util.StringTokenizer; +import java.util.concurrent.ThreadLocalRandom; + +public class Test { + + private File file, file1, expBox; + // https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=? quotes + public Test() { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + System.out.println(Arrays.toString(ge.getAvailableFontFamilyNames())); + file = new File("C:\\Users\\savit\\Desktop\\profile.png"); + file1 = new File("C:\\Users\\savit\\Desktop\\atheron-text.jpg"); + expBox = new File("C:\\Users\\savit\\Desktop\\exp-box.jpg"); + try { + test(new File("C:\\Users\\savit\\Desktop\\newImg.png")); + } catch (IOException e) { + e.printStackTrace(); + } + coverIMG(); + } + + private java.util.List addLinebreaks(String input, int maxLineLength) { + StringTokenizer tok = new StringTokenizer(input, " "); + java.util.List list = new ArrayList<>(); + // StringBuilder output = new StringBuilder(input.length()); + int lineLen = 0; + while (tok.hasMoreTokens()) { + String word = tok.nextToken(); + + if (lineLen + word.length() > maxLineLength) { + list.add(":newLine:"); + lineLen = 0; + } + list.add(word + " "); + lineLen += word.length(); + } + return list; + } + + /** + * This method turns squared images and resizes + * @throws IOException + */ + public void test(File outputFile) throws IOException { + BufferedImage img = null; + img = ImageIO.read(file1); + int width = img.getWidth(); + BufferedImage circleBuffer = new BufferedImage(width, width, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = circleBuffer.createGraphics(); + g2.setClip(new Ellipse2D.Float(0, 0, width, width)); + g2.drawImage(img, 0, 0, width, width, null); + circleBuffer = resize(circleBuffer, 340, 340); + ImageIO.write(circleBuffer,"png", outputFile); + } + + /** + * This method resizes + * @param img + * @param newW + * @param newH + * @return + */ + public BufferedImage resize(BufferedImage img, int newW, int newH) { + Image tmp = img.getScaledInstance(newW, newH, Image.SCALE_SMOOTH); + BufferedImage dimg = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB); + + Graphics2D g2d = dimg.createGraphics(); + g2d.drawImage(tmp, 0, 0, null); + g2d.dispose(); + + return dimg; + } + + /** + * This method turns original image into image WITH profile pic + * @return File + */ + private void coverIMG() { + try { + BufferedImage img = null; + try { + img = ImageIO.read(file); + } catch (IOException ex) { + return; + } + + Graphics2D graphics2D = (Graphics2D) img.getGraphics(); + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 75)); + // Profile Pic + graphics2D.drawImage(ImageIO.read(new File("C:\\Users\\savit\\Desktop\\newImg.png")), 50, 43, null); + String name = "itsTheSavvySavageINHD"; + // 900 is pretty much the beginning for 10 string chars + int x = 1075; + if (name.length() > 10 && name.length() < 20) { + x = 1180; + } else if (name.length() > 20) { + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 50)); + name = name.substring(0, 17) + "..."; + //x = 1180; + } + x = x - graphics2D.getFontMetrics().stringWidth(name); + graphics2D.drawString(name, x, 182); + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 50)); + Random r = ThreadLocalRandom.current(); + graphics2D.drawString(r.nextBoolean() ? "Premium User" : "Regular User", 725, 245); + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 75)); + graphics2D.drawString("24", 1280, 355); + + graphics2D.setFont(new Font("Lato Hairline", Font.PLAIN, 50)); + + graphics2D.drawString("Total Experience", 330, 450); + graphics2D.drawString("Global Rank", 330, 550); + graphics2D.drawString("Tokens", 330, 650); + + + graphics2D.drawString("24,061", 1140, 450); + graphics2D.drawString("#3", 1240, 550); + graphics2D.drawString("3,461", 1170, 650); + + graphics2D.setFont(new Font("Lato Light", Font.PLAIN, 50)); + graphics2D.drawString("5800 / 6000", 660, 345); + graphics2D.setFont(new Font("Lato Light", Font.PLAIN, 30)); + java.util.List list = addLinebreaks("How far you go in life depends on you being tender with the young, compassionate with the aged, " + + "sympathetic with the striving and tolerant of the weak and the strong. Because someday in life you will have been all of these.", 60); + int i = 750; + StringBuilder b = new StringBuilder(); + for (String string : list ) { + if (string.equalsIgnoreCase(":newLine:")) { + graphics2D.drawString(b.toString().trim(), 330, i); + i += 40; + b = new StringBuilder(); + continue; + } + b.append(string); + } + + graphics2D.setFont(new Font("Lato Light", Font.PLAIN, 25)); + graphics2D.drawString("- George Washington Carver",330, 900); + + BufferedImage badgeOne = ImageIO.read(new File("C:\\Users\\savit\\Desktop\\Badges\\patreon.png")); + graphics2D.drawImage(badgeOne, 1231, 924, 61, 71, null); + + BufferedImage badgeTwo = ImageIO.read(new File("C:\\Users\\savit\\Desktop\\Badges\\contributor-staff.png")); + graphics2D.drawImage(badgeTwo, 981, 922, 61, 71, null); + + BufferedImage badgeThree = ImageIO.read(new File("C:\\Users\\savit\\Desktop\\Badges\\contributor-user.png")); // correct + graphics2D.drawImage(badgeThree, 1105, 922, 61, 71, null); + /*for (int ii = 0; ii < 10; ii++) { + graphics2D.drawImage(ImageIO.read(expBox), (350 + (ii * 80)), 345, null); + }*/ + File outputfile = new File("C:\\Users\\savit\\Desktop\\color.png"); + ImageIO.write(img, "png", outputfile); + } catch (Exception ignored) { + } + } + + public static void main(String[] args) { + new Test(); + } +}