use of com.github.vaerys.objects.RewardRoleObject in project DiscordSailv2 by Vaerys-Dawn.
the class GuildConfig method lowestReward.
public RewardRoleObject lowestReward() {
validateRoles();
RewardRoleObject lowest = null;
for (RewardRoleObject r : rewardRoles) {
if (lowest == null) {
lowest = r;
} else {
if (lowest.getLevel() > r.getLevel()) {
lowest = r;
}
}
}
return lowest;
}
use of com.github.vaerys.objects.RewardRoleObject in project DiscordSailv2 by Vaerys-Dawn.
the class GuildConfig method getAllRewards.
public ArrayList<RewardRoleObject> getAllRewards(long currentLevel) {
validateRoles();
ArrayList<RewardRoleObject> rewards = new ArrayList<>();
for (RewardRoleObject r : rewardRoles) {
if (r.getLevel() <= currentLevel) {
rewards.add(r);
}
}
return rewards;
}
use of com.github.vaerys.objects.RewardRoleObject in project DiscordSailv2 by Vaerys-Dawn.
the class ManagePixelRoles method execute.
@Override
public String execute(String args, CommandObject command) {
if (args.equalsIgnoreCase("list")) {
XEmbedBuilder builder = new XEmbedBuilder(command);
builder.withTitle("Pixel Roles");
IRole xpDenied = command.guild.getXPDeniedRole();
IRole topTen = command.guild.getTopTenRole();
List<RewardRoleObject> rewardRoles = command.guild.config.getRewardRoles();
if (xpDenied == null && topTen == null && rewardRoles.size() == 0) {
return "> No roles are set up.\n" + missingArgs(command);
}
String desc = "";
if (rewardRoles.size() != 0) {
desc += "**Reward Roles**";
for (RewardRoleObject r : rewardRoles) {
desc += "\n> **" + command.guild.getRoleByID(r.getRoleID()).getName() + "** -> Level: **" + r.getLevel() + "**";
}
desc += "\n\n";
}
if (topTen != null) {
desc += "**Top Ten Role**: " + topTen.getName() + "\n\n";
}
if (xpDenied != null) {
desc += "**Pixel Denied Role**: " + xpDenied.getName();
}
builder.withDesc(desc);
builder.send(command.channel);
return null;
}
SplitFirstObject mode = new SplitFirstObject(args);
IRole role = GuildHandler.getRoleFromName(mode.getRest(), command.guild.get());
if (role == null) {
return "> **" + mode.getRest() + "** is not a valid Role name.";
}
try {
long level = Long.parseLong(mode.getFirstWord());
if (level > 256 || level <= 0) {
return "> Level must be between 1-256.";
}
for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
if (r.getLevel() == level) {
return "> That level already has a reward set.";
}
if (r.getRoleID() == role.getLongID()) {
r.setLevel(level);
return "> Level to obtain **" + role.getName() + "** is now set to level **" + level + "**.";
}
}
command.guild.config.getRewardRoles().add(new RewardRoleObject(role.getLongID(), level));
return "> The role **" + role.getName() + "** will now be awarded at level **" + level + "**.";
} catch (NumberFormatException e) {
switch(mode.getFirstWord().toLowerCase()) {
case "xpdenied":
for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
if (r.getRoleID() == role.getLongID()) {
return "> **" + role.getName() + "** is already set as a reward role.";
}
}
if (role.getLongID() == command.guild.config.topTenRoleID) {
return "> **" + role.getName() + "** is already set as the server's TopTen role.";
}
command.guild.config.xpDeniedRoleID = role.getLongID();
return "> **" + role.getName() + "** is now the server's XpDenied role.";
case "topten":
for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
if (r.getRoleID() == role.getLongID()) {
return "> **" + role.getName() + "** is already set as a reward role.";
}
}
if (role.getLongID() == command.guild.config.xpDeniedRoleID) {
return "> **" + role.getName() + "** is already set as the server's xpDenied role.";
}
command.guild.config.topTenRoleID = role.getLongID();
return "> **" + role.getName() + "** is now the server's TopTen role.";
case "remove":
if (role.getLongID() == command.guild.config.xpDeniedRoleID) {
command.guild.config.xpDeniedRoleID = -1;
return "> **" + role.getName() + "** is no longer the server's xpDenied role.";
} else if (role.getLongID() == command.guild.config.topTenRoleID) {
command.guild.config.topTenRoleID = -1;
return "> **" + role.getName() + "** is no longer the server's Top Ten role.";
}
for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
if (r.getRoleID() == role.getLongID()) {
command.guild.config.getRewardRoles().remove(r);
return "> **" + role.getName() + "** is no longer set as a reward role.";
}
}
return "> **" + role.getName() + "** is not a valid Pixel role.";
default:
return "> Invalid Mode.\n" + modes + Utility.getCommandInfo(this, command);
}
}
}
use of com.github.vaerys.objects.RewardRoleObject in project DiscordSailv2 by Vaerys-Dawn.
the class GuildHandler method checkUsersRoles.
public static void checkUsersRoles(long id, GuildObject content) {
// don't try to edit your own roles ya butt.
if (id == Client.getClient().getOurUser().getLongID())
return;
// do code.
ProfileObject profile = content.users.getUserByID(id);
if (profile == null) {
return;
}
if (profile.getSettings().contains(DENY_AUTO_ROLE))
return;
IUser user = content.getUserByID(profile.getUserID());
if (user == null) {
return;
}
List<IRole> userRoles = user.getRolesForGuild(content.get());
if (content.config.readRuleReward) {
IRole ruleReward = content.getRoleByID(content.config.ruleCodeRewardID);
if (ruleReward != null) {
if (profile.getSettings().contains(UserSetting.READ_RULES)) {
userRoles.add(ruleReward);
} else {
userRoles.remove(ruleReward);
}
}
}
if (content.config.modulePixels && content.config.xpGain) {
// remove all rewardRoles to prep for checking.
ListIterator iterator = userRoles.listIterator();
while (iterator.hasNext()) {
IRole role = (IRole) iterator.next();
if (content.config.isRoleReward(role.getLongID())) {
iterator.remove();
}
}
// add all roles that the user should have.
ArrayList<RewardRoleObject> allRewards = content.config.getAllRewards(profile.getCurrentLevel());
for (RewardRoleObject r : allRewards) {
userRoles.add(Globals.getClient().getRoleByID(r.getRoleID()));
}
// add the top ten role if they should have it.
IRole topTenRole = content.get().getRoleByID(content.config.topTenRoleID);
if (topTenRole != null) {
long rank = PixelHandler.rank(content.users, content.get(), user.getLongID());
if (rank <= 10 && rank > 0) {
userRoles.add(topTenRole);
}
}
}
// only do a role update if the role count changes
List<IRole> currentRoles = user.getRolesForGuild(content.get());
if (!currentRoles.containsAll(userRoles) || currentRoles.size() != userRoles.size()) {
RequestHandler.roleManagement(user, content.get(), userRoles);
}
}
use of com.github.vaerys.objects.RewardRoleObject in project DiscordSailv2 by Vaerys-Dawn.
the class TransferLevels method execute.
@Override
public String execute(String args, CommandObject command) {
if (command.guild.config.xpGain) {
return "> Cannot transfer levels, xp gain enabled.";
}
if (command.guild.config.getRewardRoles().size() == 0) {
return "> No rewards available to grant. cannot transfer levels";
}
IMessage message = RequestHandler.sendMessage("`Working...`", command.channel.get()).get();
Utility.sortRewards(command.guild.config.getRewardRoles());
for (IUser user : command.guild.getUsers()) {
if (!user.isBot()) {
ProfileObject uObject = command.guild.users.getUserByID(user.getLongID());
if (uObject == null) {
uObject = command.guild.users.addUser(user.getLongID());
}
uObject.lastTalked = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond();
uObject.setXp(0);
uObject.setCurrentLevel(-1);
for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
if (user.getRolesForGuild(command.guild.get()).contains(r.get(command.guild))) {
uObject.setXp(r.getXp());
uObject.setCurrentLevel(r.getLevel());
}
}
GuildHandler.checkUsersRoles(uObject.getUserID(), command.guild);
}
}
RequestHandler.deleteMessage(message);
command.guild.config.xpGain = true;
return "> Transfer Complete.";
}
Aggregations