Skip to content

Commit 08ee9b4

Browse files
authored
Merge pull request #1 from iGabyTM/master
update
2 parents 9673531 + 7c5b4d9 commit 08ee9b4

File tree

8 files changed

+137
-142
lines changed

8 files changed

+137
-142
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.idea/
22
target/
3+
plugin/testServer/
34

5+
*.json
46
*.iml

bot/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<dependency>
2626
<groupId>net.dv8tion</groupId>
2727
<artifactId>JDA</artifactId>
28-
<version>4.0.0_42</version>
28+
<version>5.0.0-alpha.18</version>
2929
<exclusions>
3030
<exclusion>
3131
<groupId>club.minnced</groupId>

bot/src/main/java/io/samdev/boostsync/bot/BoostSync.java

Lines changed: 96 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -3,120 +3,107 @@
33
import io.samdev.boostsync.bot.boost.BoostManager;
44
import io.samdev.boostsync.bot.command.CommandListener;
55
import io.samdev.boostsync.common.database.BoostSyncDatabase;
6-
import net.dv8tion.jda.api.AccountType;
76
import net.dv8tion.jda.api.JDA;
87
import net.dv8tion.jda.api.JDABuilder;
98
import net.dv8tion.jda.api.entities.Guild;
9+
import net.dv8tion.jda.api.requests.GatewayIntent;
10+
import net.dv8tion.jda.api.utils.cache.CacheFlag;
1011

1112
import static io.samdev.boostsync.bot.util.Logging.info;
1213
import static io.samdev.boostsync.bot.util.Logging.severe;
1314

14-
public class BoostSync
15-
{
16-
public static void main(String[] args)
17-
{
18-
new BoostSync();
19-
}
20-
21-
private BoostSync()
22-
{
23-
if (!loadConfig())
24-
{
25-
severe("Unable to load config");
26-
return;
27-
}
28-
29-
if (!connectToDatabase())
30-
{
31-
severe("Unable to connect to database");
32-
return;
33-
}
34-
35-
if (!connectToDiscord())
36-
{
37-
severe("Unable to connect to Discord");
38-
}
39-
40-
new CommandListener(this);
41-
boostManager = new BoostManager(this);
42-
}
43-
44-
private BoostManager boostManager;
45-
46-
public BoostManager getBoostManager()
47-
{
48-
return boostManager;
49-
}
50-
51-
private BotConfig config;
52-
53-
public BotConfig getConfig()
54-
{
55-
return config;
56-
}
57-
58-
private boolean loadConfig()
59-
{
60-
config = new BotConfig(this);
61-
return config.init();
62-
}
63-
64-
private BoostSyncDatabase database;
65-
66-
public BoostSyncDatabase getDatabase()
67-
{
68-
return database;
69-
}
70-
71-
private boolean connectToDatabase()
72-
{
73-
try
74-
{
75-
database = new BoostSyncDatabase(config.getDatabaseCredentials());
76-
return true;
77-
}
78-
catch (Exception ex)
79-
{
80-
ex.printStackTrace();
81-
return false;
82-
}
83-
}
84-
85-
private JDA jda;
86-
87-
public JDA getJda()
88-
{
89-
return jda;
90-
}
91-
92-
private Guild guild;
93-
94-
public Guild getGuild()
95-
{
96-
return guild;
97-
}
98-
99-
private boolean ready = false;
100-
101-
private boolean connectToDiscord()
102-
{
103-
try
104-
{
105-
jda = new JDABuilder(AccountType.BOT)
106-
.setToken(config.getBotToken())
107-
.build();
108-
109-
jda.awaitReady();
110-
111-
info("Connected to bot " + jda.getSelfUser().getAsTag());
112-
guild = jda.getGuildById(config.getGuildId());
113-
114-
return true;
115-
}
116-
catch (Exception ex)
117-
{
118-
ex.printStackTrace();
119-
return false;
120-
}
121-
}
15+
public class BoostSync {
16+
public static void main(String[] args) {
17+
new BoostSync();
18+
}
19+
20+
private BoostSync() {
21+
if (!loadConfig()) {
22+
severe("Unable to load config");
23+
return;
24+
}
25+
26+
if (!connectToDatabase()) {
27+
severe("Unable to connect to database");
28+
return;
29+
}
30+
31+
if (!connectToDiscord()) {
32+
severe("Unable to connect to Discord");
33+
}
34+
35+
new CommandListener(this);
36+
boostManager = new BoostManager(this);
37+
}
38+
39+
private BoostManager boostManager;
40+
41+
public BoostManager getBoostManager() {
42+
return boostManager;
43+
}
44+
45+
private BotConfig config;
46+
47+
public BotConfig getConfig() {
48+
return config;
49+
}
50+
51+
private boolean loadConfig() {
52+
config = new BotConfig(this);
53+
return config.init();
54+
}
55+
56+
private BoostSyncDatabase database;
57+
58+
public BoostSyncDatabase getDatabase() {
59+
return database;
60+
}
61+
62+
private boolean connectToDatabase() {
63+
try {
64+
database = new BoostSyncDatabase(config.getDatabaseCredentials());
65+
return true;
66+
} catch (Exception ex) {
67+
ex.printStackTrace();
68+
return false;
69+
}
70+
}
71+
72+
private JDA jda;
73+
74+
public JDA getJda() {
75+
return jda;
76+
}
77+
78+
private Guild guild;
79+
80+
public Guild getGuild() {
81+
return guild;
82+
}
83+
84+
private boolean ready = false;
85+
86+
private boolean connectToDiscord() {
87+
try {
88+
jda = JDABuilder.create(
89+
GatewayIntent.GUILD_MEMBERS,
90+
GatewayIntent.GUILD_MESSAGES,
91+
GatewayIntent.MESSAGE_CONTENT
92+
)
93+
.disableCache(CacheFlag.ACTIVITY, CacheFlag.EMOJI, CacheFlag.CLIENT_STATUS, CacheFlag.ONLINE_STATUS, CacheFlag.STICKER, CacheFlag.VOICE_STATE)
94+
.setToken(config.getBotToken())
95+
.build();
96+
97+
jda.awaitReady();
98+
99+
info("Connected to bot " + jda.getSelfUser().getAsTag());
100+
guild = jda.getGuildById(config.getGuildId());
101+
102+
return true;
103+
} catch (Exception ex) {
104+
ex.printStackTrace();
105+
return false;
106+
}
107+
}
108+
122109
}

bot/src/main/java/io/samdev/boostsync/bot/BotConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public SqlCredentials getDatabaseCredentials()
4747

4848
public TextChannel getBotChannel()
4949
{
50-
return bot.getJda().getTextChannelById(config.get("bot_channel_id").getAsString());
50+
final String id = config.get("bot_channel_id").getAsString();
51+
return id.isEmpty() ? null : bot.getJda().getTextChannelById(id);
5152
}
5253

5354
public Role getBoostingRole()

common/src/main/java/io/samdev/boostsync/common/database/BoostSyncDatabase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void removeCode(String code)
7272
public void insertSyncData(UUID uuid, SyncData data)
7373
{
7474
asyncUpdate(
75-
"INSERT INTO boostsync_synced VALUES (?,?,?,?);",
75+
"INSERT INTO boostsync_synced (uuid, discord_id, boosting, last_boost_reward) VALUES (?,?,?,?);",
7676
statement ->
7777
{
7878
statement.setString(1, uuid.toString());
@@ -159,7 +159,7 @@ private void createTables()
159159
"`discord_id` VARCHAR(20) UNIQUE KEY NOT NULL, " +
160160
"`boosting` BOOLEAN NOT NULL, " +
161161
"`last_boost_reward` BIGINT NOT NULL, " +
162-
"`one_time_reward` BOOLEAN NOT NULL" +
162+
"`one_time_reward` BOOLEAN NOT NULL DEFAULT false" +
163163
");"
164164
);
165165
}

plugin/pom.xml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
<repositories>
1717
<repository>
18-
<id>spigot-repo</id>
19-
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
18+
<id>papermc</id>
19+
<url>https://repo.papermc.io/repository/maven-public/</url>
2020
</repository>
2121

2222
<repository>
2323
<id>placeholderapi-repo</id>
24-
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
24+
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
2525
</repository>
2626

2727
<repository>
@@ -31,11 +31,11 @@
3131
</repositories>
3232

3333
<dependencies>
34-
<!-- Spigot API -->
34+
<!-- Paper API -->
3535
<dependency>
36-
<groupId>org.spigotmc</groupId>
37-
<artifactId>spigot-api</artifactId>
38-
<version>1.8.8-R0.1-SNAPSHOT</version>
36+
<groupId>io.papermc.paper</groupId>
37+
<artifactId>paper-api</artifactId>
38+
<version>1.19.2-R0.1-SNAPSHOT</version>
3939
<scope>provided</scope>
4040
</dependency>
4141

@@ -78,5 +78,15 @@
7878
</includes>
7979
</resource>
8080
</resources>
81+
<plugins>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-jar-plugin</artifactId>
85+
<version>2.3.1</version>
86+
<configuration>
87+
<outputDirectory>./testServer/plugins</outputDirectory>
88+
</configuration>
89+
</plugin>
90+
</plugins>
8191
</build>
8292
</project>

plugin/src/main/java/io/samdev/boostsync/plugin/util/Message.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.samdev.boostsync.common.util.UtilString;
44
import io.samdev.boostsync.plugin.BoostSync;
5+
import net.kyori.adventure.text.minimessage.MiniMessage;
56
import org.bukkit.ChatColor;
67
import org.bukkit.command.CommandSender;
78

@@ -35,7 +36,7 @@ public void send(CommandSender sender, Object... params)
3536
{
3637
if (value != null && !value.isEmpty())
3738
{
38-
sender.sendMessage(UtilString.formatArgs(value, params));
39+
sender.sendMessage(MiniMessage.miniMessage().deserialize(UtilString.formatArgs(value, params)));
3940
}
4041
}
4142

@@ -44,27 +45,21 @@ public static void init(BoostSync plugin)
4445
{
4546
for (Message message : values())
4647
{
47-
Object object = plugin.getConfig().get("messages." + message.name().toLowerCase());
48+
String value;
4849

49-
if (object == null)
50-
{
51-
plugin.getLogger().severe("value missing for message " + message.name());
52-
continue;
50+
if (plugin.getConfig().isList("messages." + message.name().toLowerCase())) {
51+
value = String.join("\n", plugin.getConfig().getStringList("messages." + message.name().toLowerCase()));
52+
} else {
53+
value = plugin.getConfig().getString("messages." + message.name().toLowerCase());
5354
}
5455

55-
String value = object instanceof String ?
56-
(String) object :
57-
object instanceof List<?> ?
58-
String.join("\n", (List<String>) object) :
59-
null;
60-
6156
if (value == null)
6257
{
6358
plugin.getLogger().severe("invalid data type for message " + message.name());
6459
continue;
6560
}
6661

67-
message.value = ChatColor.translateAlternateColorCodes('&', value);
62+
message.value = value;
6863
}
6964
}
7065
}

plugin/src/main/resources/config.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ sync:
3333
- "[CONSOLECOMMAND] give %player_name% emerald"
3434

3535
messages:
36-
command_link_player_only: "&cOnly players can use this command"
37-
command_link_usage: "&eUsage: /link"
38-
command_link_already_synced: "&aYour account is already linked"
39-
command_link_success: "&aYour code is &b{code}&a, use it within 60 seconds"
36+
command_link_player_only: "<red>Only players can use this command"
37+
command_link_usage: "<yellow>Usage: /link"
38+
command_link_already_synced: "<green>Your account is already linked"
39+
command_link_success: "<green>Your code is <aqua>{code}<green>, use it within 60 seconds"
4040

4141
command_unlink_permission: "boostsync.unlink"
42-
command_unlink_no_permission: "&cYou don't have permission to use this command"
43-
command_unlink_usage: "&eUsage: /unlink <player>"
44-
command_unlink_not_synced: "&cThat player's account is not linked"
45-
command_unlink_success: "&aUnlinked {player}'s account"
42+
command_unlink_no_permission: "<red>You don't have permission to use this command"
43+
command_unlink_usage: "<yellow>Usage: /unlink <player>"
44+
command_unlink_not_synced: "<red>That player's account is not linked"
45+
command_unlink_success: "<green>Unlinked {player}'s account"
4646

47-
account_linked: "&aYour Discord account is now linked!"
47+
account_linked: "<green>Your Discord account is now linked!"

0 commit comments

Comments
 (0)