Skip to content

Commit

Permalink
Merge pull request #11 from Chickenpowerrr/develop
Browse files Browse the repository at this point in the history
1.3.1 update
  • Loading branch information
Chickenpowerrr authored Aug 16, 2019
2 parents e56cfc8 + cd31660 commit a829fa4
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 54 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranksync</artifactId>
<groupId>com.gmail.chickenpowerrr</groupId>
<version>1.3.0</version>
<version>1.3.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,17 @@ public interface RankFactory<R> {
* @return if the given rank is a valid platform rank according to the RankHelpers
*/
boolean isValidRank(Rank rank);

/**
* Updates if the factory should throw warnings when the bot's permissions are insufficient
*
* @param shouldThrow if the factory should throw warnings when the bot's permissions are
* insufficient
*/
void setShouldThrowPermissionWarnings(boolean shouldThrow);

/**
* Returns if the helper should give warnings when the bot doesn't have high enough permissions
*/
boolean shouldThrowPermissionWarnings();
}
41 changes: 36 additions & 5 deletions bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>ranksync</artifactId>
<groupId>com.gmail.chickenpowerrr</groupId>
<version>1.3.0</version>
<version>1.3.1</version>
</parent>

<groupId>com.gmail.chickenpowerrr.ranksync</groupId>
Expand All @@ -20,6 +20,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
Expand All @@ -43,7 +44,7 @@
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<finalName>RankSync-Bungee-${version}</finalName>
<finalName>RankSync-Bungee-${project.version}</finalName>
<relocations>
<relocation>
<pattern>org.json</pattern>
Expand All @@ -54,6 +55,36 @@
<pattern>org.bstats</pattern>
<shadedPattern>com.gmail.chickenpowerrr.ranksync.lib.bstats</shadedPattern>
</relocation>

<relocation>
<pattern>net.dv8tion</pattern>
<shadedPattern>com.gmail.chickenpowerrr.ranksync.lib.jda</shadedPattern>
</relocation>

<relocation>
<pattern>com.iwepp</pattern>
<shadedPattern>com.gmail.chickenpowerrr.ranksync.lib.iwepp</shadedPattern>
</relocation>

<relocation>
<pattern>com.neovisionaries.ws</pattern>
<shadedPattern>com.gmail.chickenpowerrr.ranksync.lib.ws</shadedPattern>
</relocation>

<relocation>
<pattern>gnu.trove</pattern>
<shadedPattern>com.gmail.chickenpowerrr.ranksync.lib.trove</shadedPattern>
</relocation>

<relocation>
<pattern>okhttp3</pattern>
<shadedPattern>com.gmail.chickenpowerrr.ranksync.lib.okhttp</shadedPattern>
</relocation>

<relocation>
<pattern>okio</pattern>
<shadedPattern>com.gmail.chickenpowerrr.ranksync.lib.okio</shadedPattern>
</relocation>
</relocations>
</configuration>

Expand Down Expand Up @@ -98,7 +129,7 @@
<dependency>
<groupId>com.gmail.chickenpowerrr.ranksync</groupId>
<artifactId>manager</artifactId>
<version>${parent.version}</version>
<version>${project.parent.version}</version>
<scope>compile</scope>

<exclusions>
Expand All @@ -112,14 +143,14 @@
<dependency>
<groupId>com.gmail.chickenpowerrr.ranksync</groupId>
<artifactId>server</artifactId>
<version>${parent.version}</version>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.gmail.chickenpowerrr.ranksync</groupId>
<artifactId>api</artifactId>
<version>${parent.version}</version>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ public void shutdown(String... reason) {
*/
@Override
public String getConfigString(String key) {
return this.configuration.getString(key);
if (this.configuration.contains(key)) {
return this.configuration.getString(key);
} else if (key.equals("database.type")) {
return "yaml";
} else {
return "";
}
}

/**
Expand Down Expand Up @@ -155,7 +161,18 @@ public int getConfigInt(String key) {
*/
@Override
public boolean getConfigBoolean(String key) {
return this.configuration.getBoolean(key);
if (this.configuration.contains(key)) {
return this.configuration.getBoolean(key);
} else {
switch (key) {
case "update_non_synced":
case "discord.permission-warnings":
return true;
case "sync_names":
default:
return false;
}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions bungee/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ${parent.name}
name: ${project.parent.name}
version: ${project.version}
main: ${project.groupId}.bungeecord.${parent.name}Plugin
main: ${project.groupId}.bungeecord.${project.parent.name}Plugin
author: Chickenpowerrr
description: ${project.description}
softdepend: [LuckPerms]
4 changes: 2 additions & 2 deletions discord/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranksync</artifactId>
<groupId>com.gmail.chickenpowerrr</groupId>
<version>1.3.0</version>
<version>1.3.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -24,7 +24,7 @@
<dependency>
<groupId>com.gmail.chickenpowerrr.ranksync</groupId>
<artifactId>api</artifactId>
<version>${parent.version}</version>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public void enable(JDA jda) {
if (this.guild != null) {
this.rankFactory = com.gmail.chickenpowerrr.ranksync.discord.rank.RankFactory
.getInstance(this, guild);
this.rankFactory
.setShouldThrowPermissionWarnings(this.properties.getBoolean("permission_warnings"));
this.playerFactory = com.gmail.chickenpowerrr.ranksync.discord.player.PlayerFactory
.getInstance(this, guild);
this.databaseFactory = com.gmail.chickenpowerrr.ranksync.discord.data.DatabaseFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package com.gmail.chickenpowerrr.ranksync.discord.player;

import com.gmail.chickenpowerrr.ranksync.api.bot.Bot;
import com.gmail.chickenpowerrr.ranksync.api.RankSyncApi;
import com.gmail.chickenpowerrr.ranksync.api.bot.Bot;
import com.gmail.chickenpowerrr.ranksync.api.event.BotPlayerRanksUpdateEvent;
import com.gmail.chickenpowerrr.ranksync.api.name.NameResource;
import com.gmail.chickenpowerrr.ranksync.api.rank.Rank;
import com.gmail.chickenpowerrr.ranksync.api.event.BotPlayerRanksUpdateEvent;
import com.gmail.chickenpowerrr.ranksync.discord.rank.RankFactory;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Role;

import java.util.Collection;
import java.util.HashSet;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.exceptions.HierarchyException;

/**
Expand All @@ -24,7 +22,6 @@
* @author Chickenpowerrr
* @since 1.0.0
*/
@Slf4j
public class Player implements com.gmail.chickenpowerrr.ranksync.api.player.Player {

private final Member member;
Expand Down Expand Up @@ -122,9 +119,11 @@ public void setUsername(String username) {
try {
this.member.getGuild().getController().setNickname(this.member, username).queue();
} catch (HierarchyException e) {
log.warn(
"Can't update the username for Discord user: " + this.member.getEffectiveName()
+ " since their rank is too high");
if (this.rankFactory.shouldThrowPermissionWarnings()) {
System.out.println(
"Can't update the username for Discord user: " + this.member.getEffectiveName()
+ " since their rank is too high");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.OptionalInt;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Role;
Expand All @@ -34,13 +35,17 @@ public class RankFactory implements com.gmail.chickenpowerrr.ranksync.api.rank.R
private final Bot<?, Role> bot;
private final Collection<RankHelper> rankHelpers = new HashSet<>();

@Setter
private boolean shouldThrowPermissionWarnings;

/**
* @param bot the Bot that is running
* @param guild the Guild the Bot is running on
*/
private RankFactory(Bot<?, Role> bot, Guild guild) {
this.bot = bot;
this.guild = guild;
this.shouldThrowPermissionWarnings = true;
}

/**
Expand Down Expand Up @@ -175,21 +180,25 @@ public void addRankHelper(RankHelper rankHelper) {
.filter(role -> role.getPosition() >= highestRole.getAsInt()).map(Role::getName)
.collect(Collectors.joining(", "));
if (!invalidPriorities.isEmpty()) {
if (shouldThrowPermissionWarnings()) {
System.out.println("===================================");
System.out.println("RankSync Warning:");
System.out.println(
"The Discord bot doesn't have a high enough rank priority to issue the following ranks:.");
System.out.println(invalidPriorities);
System.out.println("For more information please follow this guide: ");
System.out
.println("https://github.com/Chickenpowerrr/RankSync/wiki/Getting-a-Discord-Token");
System.out.println("===================================");
}
}
} else {
if (shouldThrowPermissionWarnings()) {
System.out.println("===================================");
System.out.println("RankSync Warning:");
System.out.println(
"The Discord bot doesn't have a high enough rank priority to issue the following ranks:.");
System.out.println(invalidPriorities);
System.out.println("For more information please follow this guide: ");
System.out
.println("https://github.com/Chickenpowerrr/RankSync/wiki/Getting-a-Discord-Token");
System.out.println("The Discord bot doesn't have a rank.");
System.out.println("===================================");
}
} else {
System.out.println("===================================");
System.out.println("RankSync Warning:");
System.out.println("The Discord bot doesn't have a rank.");
System.out.println("===================================");
}
}

Expand All @@ -204,4 +213,12 @@ public boolean isValidRank(Rank rank) {
return this.rankHelpers.stream()
.anyMatch(rankHelper -> rankHelper.isSynchronized(this.bot, rank));
}

/**
* Returns if the helper should give warnings when the bot doesn't have high enough permissions
*/
@Override
public boolean shouldThrowPermissionWarnings() {
return this.shouldThrowPermissionWarnings;
}
}
6 changes: 3 additions & 3 deletions manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranksync</artifactId>
<groupId>com.gmail.chickenpowerrr</groupId>
<version>1.3.0</version>
<version>1.3.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,14 +16,14 @@
<dependency>
<groupId>com.gmail.chickenpowerrr.ranksync</groupId>
<artifactId>discord</artifactId>
<version>${parent.version}</version>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.gmail.chickenpowerrr.ranksync</groupId>
<artifactId>api</artifactId>
<version>${parent.version}</version>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>ranksync</artifactId>
<name>RankSync</name>
<packaging>pom</packaging>
<version>1.3.0</version>
<version>1.3.1</version>
<modules>
<module>api</module>
<module>discord</module>
Expand All @@ -18,6 +18,11 @@
<module>bungee</module>
</modules>

<properties>
<java.version>8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
Expand Down
6 changes: 3 additions & 3 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranksync</artifactId>
<groupId>com.gmail.chickenpowerrr</groupId>
<version>1.3.0</version>
<version>1.3.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -23,14 +23,14 @@
<dependency>
<groupId>com.gmail.chickenpowerrr.ranksync</groupId>
<artifactId>manager</artifactId>
<version>${parent.version}</version>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.gmail.chickenpowerrr.ranksync</groupId>
<artifactId>api</artifactId>
<version>${parent.version}</version>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ default void enable() {
.addProperty("guild_id", getConfigLong("discord.guild-id"))
.addProperty("update_non_synced", getConfigBoolean("discord.update-non-synced"))
.addProperty("sync_names", getConfigBoolean("discord.sync-names"))
.addProperty("permission_warnings", getConfigBoolean("discord.permission-warnings"))
.addProperty("type", getConfigString("database.type"))
.addProperty("max_pool_size", getConfigInt("database.sql.max-pool-size"))
.addProperty("host", getConfigString("database.sql.host"))
Expand Down
Loading

0 comments on commit a829fa4

Please sign in to comment.