Recent Update (not descriptive)

This commit is contained in:
Savvy 2017-10-14 17:07:56 -04:00
parent c68102bbc7
commit 8862785fd5
13 changed files with 435 additions and 74 deletions

View File

@ -13,6 +13,7 @@ import me.savvy.rixa.commands.mod.DeleteMessagesCommand;
import me.savvy.rixa.commands.mod.MuteCommand; import me.savvy.rixa.commands.mod.MuteCommand;
import me.savvy.rixa.commands.mod.PurgeMessagesCommand; import me.savvy.rixa.commands.mod.PurgeMessagesCommand;
import me.savvy.rixa.commands.mod.RaidModeCommand; 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.commands.owner.OwnerCommand;
import me.savvy.rixa.data.database.sql.SQLBuilder; import me.savvy.rixa.data.database.sql.SQLBuilder;
import me.savvy.rixa.data.database.sql.other.DatabaseTables; 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("databaseName"),
config.getJsonObject().getJSONObject("sql").getString("hostName")); config.getJsonObject().getJSONObject("sql").getString("hostName"));
Arrays.stream(DatabaseTables.values()).forEach(databaseTables -> { 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 { try {
database.executeUpdate(databaseTables.getQuery()); database.executeUpdate(databaseTables.getQuery());
getInstance().getLogger().info("Done checking " + databaseTables.toString()); System.out.println("Done checking " + databaseTables.toString());
} catch (SQLException e) { } catch (SQLException e) {
getInstance().getLogger().severe("Could not create table: " + databaseTables.toString()); getInstance().getLogger().severe("Could not create table: " + databaseTables.toString());
e.printStackTrace(); e.printStackTrace();
@ -137,7 +138,8 @@ public class Rixa {
new ConfigCommand(), new UrbanDictionaryCommand(), new YoutubeCommand(), new ConfigCommand(), new UrbanDictionaryCommand(), new YoutubeCommand(),
new AddRoleCommand(), new RemoveRoleCommand(), new LevelsCommand(), new AddRoleCommand(), new RemoveRoleCommand(), new LevelsCommand(),
new LeaderboardCommand(), new RaidModeCommand(), new OwnerCommand(), 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()); register(new HelpReaction(), new ConfigReaction(), new LeaderboardReaction());
} }

View File

@ -42,9 +42,9 @@ public class AddRoleCommand implements CommandExec {
return; return;
} }
try { try {
int users = event.getMessage().getMentionedUsers().size(); int users = memberList.size();
memberList.forEach(user -> event.getGuild().getController().addRolesToMember(user, roleList).queue()); 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) { } catch (PermissionException ex) {
new MessageBuilder(event.getMember().getAsMention() + ", sorry I do not have permission for this!").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder(event.getMember().getAsMention() + ", sorry I do not have permission for this!").setColor(event.getMember().getColor()).queue(event.getChannel());
} }

View File

@ -42,7 +42,7 @@ public class RemoveRoleCommand implements CommandExec {
return; return;
} }
try { try {
int users = event.getMessage().getMentionedUsers().size(); int users = memberList.size();
memberList.forEach(user -> event.getGuild().getController().removeRolesFromMember(user, roleList).queue()); 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()); new MessageBuilder("Successfully removed `" + roleList.size() + "` role(s) from " + users + " user(s)!").setColor(event.getMember().getColor()).queue(event.getChannel());
} catch (PermissionException ex) { } catch (PermissionException ex) {

View File

@ -16,10 +16,14 @@ public class FeaturesCommand implements CommandExec {
@Override @Override
@Command(mainCommand = "features", @Command(mainCommand = "features",
description = "List Rixa Features!", description = "List Rixa Features!",
aliases = {"feature"},
channelType = ChannelType.TEXT) channelType = ChannelType.TEXT)
public void execute(GuildMessageReceivedEvent event) { public void execute(GuildMessageReceivedEvent event) {
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild()); 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( new MessageBuilder(
features.length == 0 ? "There are currently no features listed." : features.length == 0 ? "There are currently no features listed." :
"Rixa Features: " + String.join("\n", features "Rixa Features: " + String.join("\n", features

View File

@ -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()); new MessageBuilder("Levels are not enabled on this server!").setColor(event.getMember().getColor()).queue(event.getChannel());
return; return;
} }
List<Member> memberList = Utils.memberSearch(event.getGuild(), event.getMessage().getContent(), false);
if (event.getMessage().getContent().split(" ").length == 2) { 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 <user>].").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + rixaGuild.getGuildSettings().getPrefix() + "rank <user>].").setColor(event.getMember().getColor()).queue(event.getChannel());
return; return;
} }
List<Member> memberList = Utils.memberSearch(event.getGuild(), event.getMessage().getContent(), false);
if (memberList.get(0) == null) { if (memberList.get(0) == null) {
new MessageBuilder(event.getMember().getAsMention() + ", couldn't find user.").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder(event.getMember().getAsMention() + ", couldn't find user.").setColor(event.getMember().getColor()).queue(event.getChannel());
return; return;

View File

@ -16,9 +16,10 @@ public class ModulesCommand implements CommandExec {
@Override @Override
@Command(mainCommand = "modules", @Command(mainCommand = "modules",
description = "List Rixa Modules!", description = "List Rixa Modules!",
aliases = {"module"},
channelType = ChannelType.TEXT) channelType = ChannelType.TEXT)
public void execute(GuildMessageReceivedEvent event) { public void execute(GuildMessageReceivedEvent event) {
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild()); 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());
} }
} }

View File

@ -102,7 +102,9 @@ public class MusicCommand implements CommandExec {
return; return;
} }
try { 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) { } catch (PermissionException e) {
if (e.getPermission() == Permission.VOICE_CONNECT) { 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()); new MessageBuilder("I do not have permission to join the requested voice channel.").setColor(event.getMember().getColor()).queue(event.getChannel());

View File

@ -3,17 +3,19 @@ package me.savvy.rixa.commands.owner;
import me.savvy.rixa.commands.handlers.Command; import me.savvy.rixa.commands.handlers.Command;
import me.savvy.rixa.commands.handlers.CommandExec; import me.savvy.rixa.commands.handlers.CommandExec;
import me.savvy.rixa.commands.handlers.CommandType; import me.savvy.rixa.commands.handlers.CommandType;
import me.savvy.rixa.guild.user.profile.Profile;
import me.savvy.rixa.utils.MessageBuilder; import me.savvy.rixa.utils.MessageBuilder;
import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import java.io.IOException;
public class CleanGuildCommand implements CommandExec { public class CleanGuildCommand implements CommandExec {
@Override @Override
@Command(mainCommand = "cleanguilds", @Command(mainCommand = "profile",
description = "Clean Inactive Guilds From Rixa's Database!", description = "Profile",
channelType = ChannelType.TEXT, channelType = ChannelType.TEXT,
showInHelp = false,
type = CommandType.BOT_OWNER) type = CommandType.BOT_OWNER)
public void execute(GuildMessageReceivedEvent event) { public void execute(GuildMessageReceivedEvent event) {
if (!event.getAuthor().getId().equalsIgnoreCase("202944101333729280")) { if (!event.getAuthor().getId().equalsIgnoreCase("202944101333729280")) {
@ -21,51 +23,10 @@ public class CleanGuildCommand implements CommandExec {
.setColor(event.getMember().getColor()).queue(event.getChannel()); .setColor(event.getMember().getColor()).queue(event.getChannel());
return; 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 { try {
while (rs.next()) { event.getChannel().sendFile(Profile.getInstance().get(event.getMember()), null).queue();
if (event.getJDA().getGuildById(rs.getString("guild_id")) == null) { } catch (IOException e) {
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) {
e.printStackTrace(); e.printStackTrace();
} }
return r == Result.TRUE;*/
return true;
} }
} }

View File

@ -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'," + 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'," + " `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'," + " `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," + 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," + " `option_1` varchar(255) DEFAULT NULL, `option_2` varchar(255) DEFAULT NULL, `option_3` varchar(255) DEFAULT NULL," +

View File

@ -24,7 +24,6 @@ import net.dv8tion.jda.core.hooks.SubscribeEvent;
import java.awt.*; import java.awt.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -194,22 +193,26 @@ public class MessageEvent {
@SubscribeEvent @SubscribeEvent
public void onGuildReact(GuildMessageReactionAddEvent event) { public void onGuildReact(GuildMessageReactionAddEvent event) {
if (event.getGuild() == null) return; try {
if (event.getUser().isBot()) return; if (event.getGuild() == null) return;
Message message = event.getChannel().getMessageById(event.getMessageId()).complete(); if (event.getUser().isBot()) return;
if (message == null || message.getEmbeds().size() != 1) return; Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
MessageEmbed embed = message.getEmbeds().get(0); if (message == null || message.getEmbeds().size() != 1) return;
if (StringUtils.isNullOrEmpty(embed.getTitle())) return; MessageEmbed embed = message.getEmbeds().get(0);
String[] titleSplit = embed.getTitle().split(": "); if (StringUtils.isNullOrEmpty(embed.getTitle())) return;
System.out.println(Arrays.toString(titleSplit)); String[] titleSplit = embed.getTitle().split(": ");
if (ReactionManager.getReactions().containsKey(titleSplit[0])) { if (ReactionManager.getReactions().containsKey(titleSplit[0])) {
ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]); ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]);
Method m = reactRegistrar.getMethod(); Method m = reactRegistrar.getMethod();
try { try {
m.invoke(reactRegistrar.getExecutor(), event); m.invoke(reactRegistrar.getExecutor(), event);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}
} }
} catch (PermissionException pex) {
if (pex.getPermission() == Permission.MESSAGE_READ) return;
pex.printStackTrace();
} }
} }
} }

View File

@ -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<String> 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<String> addLinebreaks(String input, int maxLineLength) {
StringTokenizer tok = new StringTokenizer(input, " ");
java.util.List<String> 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;
}
}

View File

@ -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() {
}
}

View File

@ -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<String> addLinebreaks(String input, int maxLineLength) {
StringTokenizer tok = new StringTokenizer(input, " ");
java.util.List<String> 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<String> 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();
}
}