diff --git a/pom.xml b/pom.xml
index 111aeec..876c353 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.samifying
main-plugin
- 1.1
+ 1.2
jar
MainPlugin
@@ -91,11 +91,6 @@
spark-core
2.9.3
-
- com.google.code.gson
- gson
- 2.8.6
-
net.dv8tion
JDA
@@ -112,5 +107,10 @@
logback-classic
1.2.3
+
+ com.googlecode.json-simple
+ json-simple
+ 1.1.1
+
diff --git a/src/main/java/com/samifying/plugin/DatabaseAccess.java b/src/main/java/com/samifying/plugin/DatabaseAccess.java
index faa9774..c0d2d6f 100644
--- a/src/main/java/com/samifying/plugin/DatabaseAccess.java
+++ b/src/main/java/com/samifying/plugin/DatabaseAccess.java
@@ -2,7 +2,6 @@
import java.io.IOException;
import java.sql.*;
-import java.time.Instant;
public class DatabaseAccess {
@@ -14,11 +13,10 @@ public DatabaseAccess() throws SQLException, IOException {
}
public void insertData(String uuid, String discordId) throws SQLException {
- String sql = "INSERT INTO `twitch_link`.`data` (`uuid`, `discord_id`, `time`) VALUES (?, ?, ?);";
+ String sql = "INSERT INTO `twitch_link`.`data` (`uuid`, `discord_id`) VALUES (?, ?);";
PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1, uuid);
ps.setString(2, discordId);
- ps.setString(3, String.valueOf(Instant.now().toEpochMilli()));
ps.executeUpdate();
ps.close();
}
@@ -45,17 +43,6 @@ public String retrieveUUID(String discordId) throws SQLException {
return null;
}
- public String retrieveVerificationTimestamp(String discordId) throws SQLException {
- String sql = "SELECT `discord_id` FROM `twitch_link`.`data` WHERE discord_id=?;";
- PreparedStatement ps = connection.prepareStatement(sql);
- ps.setString(1, discordId);
- ResultSet resultSet = ps.executeQuery();
- while (resultSet.next()) {
- return resultSet.getString("timestamp");
- }
- return null;
- }
-
public void close() throws SQLException {
connection.close();
}
diff --git a/src/main/java/com/samifying/plugin/MainPlugin.java b/src/main/java/com/samifying/plugin/MainPlugin.java
index 4480999..0bee89a 100644
--- a/src/main/java/com/samifying/plugin/MainPlugin.java
+++ b/src/main/java/com/samifying/plugin/MainPlugin.java
@@ -48,7 +48,7 @@ public void onEnable() {
logger.info("Connecting to Discord API");
try {
jda = JDABuilder.createDefault(PluginData.getInstance().getDiscordToken())
- .setActivity(Activity.playing("Minecraft"))
+ .setActivity(Activity.listening("!mchelp"))
.addEventListeners(new CommandModule(this))
.addEventListeners(new FilterModule())
.build();
@@ -103,11 +103,18 @@ public void onEnable() {
@Override
public void onDisable() {
// Plugin shutdown logic
+ if (jda!=null) {
+ logger.info("Disconnecting from Discord API");
+ jda.shutdownNow();
+ }
+ logger.info("Closing the balance API endpoint");
+ Spark.stop();
}
public void handleException(Exception e) {
logger.severe("Exception occurred: " + e.getClass().getName());
logger.severe("With message: " + e.getMessage());
+ e.printStackTrace();
}
public JDA getJda() {
diff --git a/src/main/java/com/samifying/plugin/events/PlayerLogin.java b/src/main/java/com/samifying/plugin/events/PlayerLogin.java
index 4cddaae..b709d6d 100644
--- a/src/main/java/com/samifying/plugin/events/PlayerLogin.java
+++ b/src/main/java/com/samifying/plugin/events/PlayerLogin.java
@@ -5,7 +5,6 @@
import com.samifying.plugin.PluginData;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
-import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
@@ -29,14 +28,8 @@ public void onAsyncPlayerPreLoginEvent(AsyncPlayerPreLoginEvent event) {
if (guild != null) {
Member member = guild.retrieveMemberById(userId).complete();
if (member != null) {
- if (member.getRoles().stream().anyMatch(role -> role.getId().equals(PluginData.LEVEL_10_ROLE_ID))) {
- // Member has joined
- plugin.getLogger().info(String.format("Discord member %s (%s) logged in successfully", member.getEffectiveName(), member.getId()));
- plugin.getServer().broadcastMessage(
- String.format("%s%s (%s) joined as %s", ChatColor.AQUA, member.getUser().getAsTag(), member.getEffectiveName(), event.getName())
- );
- } else {
- event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "You need to be Level 10 (Bronze II) in order to play");
+ if (!member.getRoles().contains(guild.getRoleById(PluginData.MINECRAFT_ROLE_ID))) {
+ event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "You don't have permission to join");
}
} else {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "You are not a Discord server member");
diff --git a/src/main/java/com/samifying/plugin/modules/CommandModule.java b/src/main/java/com/samifying/plugin/modules/CommandModule.java
index d1ea320..5f6d6c5 100644
--- a/src/main/java/com/samifying/plugin/modules/CommandModule.java
+++ b/src/main/java/com/samifying/plugin/modules/CommandModule.java
@@ -3,6 +3,7 @@
import com.samifying.plugin.MainPlugin;
import com.samifying.plugin.PluginData;
import com.samifying.plugin.modules.commands.*;
+import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
@@ -25,14 +26,16 @@ public CommandModule(MainPlugin plugin) {
map.put("!mcstatus", status);
map.put("!seed", new SeedCommand(false, false));
map.put("!botinvite", new BotInviteCommand(false, false));
- map.put("!config", new ConfigCommand(true, true));
+ map.put("!config", new ConfigCommand(false, true));
map.put("!spawn", new SpawnCommand(false, false));
map.put("!tutorial", new TutorialCommand(false, false));
map.put("!verify", new VerifyCommand(true, false));
map.put("!whois", new WhoisCommand(true, true));
- map.put("!rcon", new RconCommand(true, true));
+ map.put("!rcon", new RconCommand(false, true));
map.put("!balance", new BalanceCommand(true, false));
map.put("!myid", new MyIdCommand(false, false));
+ map.put("!mchelp", new HelpCommand(false, false));
+ map.put("!moneyrpc", new MoneyRPCommand(false, false));
}
@Override
diff --git a/src/main/java/com/samifying/plugin/modules/commands/ConfigCommand.java b/src/main/java/com/samifying/plugin/modules/commands/ConfigCommand.java
index 8238e1e..209bab0 100644
--- a/src/main/java/com/samifying/plugin/modules/commands/ConfigCommand.java
+++ b/src/main/java/com/samifying/plugin/modules/commands/ConfigCommand.java
@@ -15,19 +15,17 @@ public ConfigCommand(boolean guildSpecific, boolean staffOnly) {
public void execute(MainPlugin plugin, Member member, TextChannel channel, String[] args) {
if (args.length > 0) {
if (args[0].equals("verification")) {
- if (args[1].equals("enable")) {
+ if (args.length == 2 && args[1].equals("enable")) {
PluginData.VERIFICATION_ENABLED = true;
channel.sendMessage("Verification has been enabled").queue();
- return;
- }
- if (args[1].equals("disable")) {
+ } else if (args.length == 2 && args[1].equals("disable")) {
PluginData.VERIFICATION_ENABLED = false;
channel.sendMessage("Verification has been disabled").queue();
- return;
+ } else {
+ channel.sendMessageFormat("Available options: `enable` or `disable`%sCurrently verification is: **%s**",
+ System.lineSeparator(), getVerificationStatus()
+ ).queue();
}
- channel.sendMessageFormat("Available options: `enable` or `disable`%sCurrently verification is: **%s**",
- System.lineSeparator(), getVerificationStatus()
- ).queue();
}
} else {
channel.sendMessage("Invalid arguments, available options: `verification`").queue();
diff --git a/src/main/java/com/samifying/plugin/modules/commands/HelpCommand.java b/src/main/java/com/samifying/plugin/modules/commands/HelpCommand.java
new file mode 100644
index 0000000..19b0e67
--- /dev/null
+++ b/src/main/java/com/samifying/plugin/modules/commands/HelpCommand.java
@@ -0,0 +1,43 @@
+package com.samifying.plugin.modules.commands;
+
+import com.samifying.plugin.MainPlugin;
+import net.dv8tion.jda.api.EmbedBuilder;
+import net.dv8tion.jda.api.entities.Member;
+import net.dv8tion.jda.api.entities.TextChannel;
+import net.dv8tion.jda.api.utils.MarkdownUtil;
+
+import java.awt.*;
+
+public class HelpCommand extends GuildCommand {
+
+ public HelpCommand(boolean guildSpecific, boolean staffOnly) {
+ super(guildSpecific, staffOnly);
+ }
+
+ @Override
+ public void execute(MainPlugin plugin, Member member, TextChannel channel, String[] args) {
+ if (args.length == 1 && args[0].equals("admin")) {
+ channel.sendMessage(new EmbedBuilder()
+ .setColor(Color.ORANGE)
+ .setTitle(MarkdownUtil.bold("Available admin commands"))
+ .addField("!config", "Configures various properties", false)
+ .addField("!rcon", "Executes a command on the Minecraft server", false)
+ .addField("!whois", "Retrieves data relating verified players", false)
+ .build()).queue();
+ return;
+ }
+ channel.sendMessage(new EmbedBuilder()
+ .setColor(Color.ORANGE)
+ .setTitle(MarkdownUtil.bold("Available commands"))
+ .addField("!balance", "Displays your balance", false)
+ .addField("!botinvite", "Displays the bot invite link", false)
+ .addField("!myid", "Displays your Discord id", false)
+ .addField("!seed", "Displays current world seed", false)
+ .addField("!spawn", "Displays current world's spawn location", false)
+ .addField("!mcstatus/!online", "Displays current Minecraft server status", false)
+ .addField("!tutorial", "Sends a link for the Minecraft server plugin tutorial playlist", false)
+ .addField("!verify", "Links your Discord account to your Minecraft account", false)
+ .addField("!moneyrpc", "Displays a link to the mod's download and tutorial page", false)
+ .build()).queue();
+ }
+}
diff --git a/src/main/java/com/samifying/plugin/modules/commands/MoneyRPCommand.java b/src/main/java/com/samifying/plugin/modules/commands/MoneyRPCommand.java
new file mode 100644
index 0000000..b62b11f
--- /dev/null
+++ b/src/main/java/com/samifying/plugin/modules/commands/MoneyRPCommand.java
@@ -0,0 +1,19 @@
+package com.samifying.plugin.modules.commands;
+
+import com.samifying.plugin.MainPlugin;
+import net.dv8tion.jda.api.entities.Member;
+import net.dv8tion.jda.api.entities.TextChannel;
+
+public class MoneyRPCommand extends GuildCommand {
+
+ public MoneyRPCommand(boolean guildSpecific, boolean staffOnly) {
+ super(guildSpecific, staffOnly);
+ }
+
+ @Override
+ public void execute(MainPlugin plugin, Member member, TextChannel channel, String[] args) {
+ channel.sendMessageFormat("You can find instructions on how to install and download this Fabric mod here:%s **%s**",
+ System.lineSeparator(),
+ "https://github.com/SamiCraft/MoneyRPC").queue();
+ }
+}
diff --git a/src/main/java/com/samifying/plugin/modules/commands/StatusCommand.java b/src/main/java/com/samifying/plugin/modules/commands/StatusCommand.java
index 56d1784..e242b7f 100644
--- a/src/main/java/com/samifying/plugin/modules/commands/StatusCommand.java
+++ b/src/main/java/com/samifying/plugin/modules/commands/StatusCommand.java
@@ -28,7 +28,7 @@ public void execute(MainPlugin plugin, Member member, TextChannel channel, Strin
channel.sendMessage(
new EmbedBuilder()
.setColor(Color.ORANGE)
- .setTitle(MarkdownUtil.bold("SERVER STATUS"))
+ .setTitle(MarkdownUtil.bold("Server status"))
.setThumbnail("https://get.samifying.com/img/server-icon.png")
.addField("Version:", server.getVersion(), true)
.addField("Online players:", online.size() + "/" + server.getMaxPlayers(), true)
diff --git a/src/main/java/com/samifying/plugin/modules/commands/VerifyCommand.java b/src/main/java/com/samifying/plugin/modules/commands/VerifyCommand.java
index 5845ed1..864757e 100644
--- a/src/main/java/com/samifying/plugin/modules/commands/VerifyCommand.java
+++ b/src/main/java/com/samifying/plugin/modules/commands/VerifyCommand.java
@@ -27,7 +27,8 @@ public VerifyCommand(boolean guildSpecific, boolean staffOnly) {
public void execute(MainPlugin plugin, Member member, TextChannel channel, String[] args) {
if (PluginData.VERIFICATION_ENABLED) {
User user = member.getUser();
- if (member.getRoles().stream().anyMatch(role -> role.getId().equals(PluginData.LEVEL_10_ROLE_ID))) {
+ Guild guild = channel.getGuild();
+ if (member.getRoles().contains(guild.getRoleById(PluginData.LEVEL_10_ROLE_ID))) {
if (args.length == 1) {
try {
// Fixing up any typos and receiving the mc uuid
@@ -65,7 +66,6 @@ public void execute(MainPlugin plugin, Member member, TextChannel channel, Strin
access.close();
// Success notification
- Guild guild = channel.getGuild();
channel.sendMessage(member.getAsMention()).embed(
new EmbedBuilder()
.setColor(Color.GREEN)
@@ -74,7 +74,7 @@ public void execute(MainPlugin plugin, Member member, TextChannel channel, Strin
.setDescription(MarkdownUtil.bold("You have successfully linked your Minecraft account. You can now join the server!"))
.addField("IP:", "play.samifying.com", false)
.addField("Username:", username, false)
- .addField("Discord ID", user.getId(), false)
+ .addField("Discord ID:", user.getId(), false)
.setFooter(guild.getName(), guild.getIconUrl())
.setTimestamp(Instant.now())
.build()
@@ -103,7 +103,7 @@ public void execute(MainPlugin plugin, Member member, TextChannel channel, Strin
.setColor(Color.ORANGE)
.setAuthor(user.getName(), null, user.getEffectiveAvatarUrl())
.setTitle(MarkdownUtil.bold("COMMAND USAGE"))
- .setDescription(MarkdownUtil.bold("This command will link your Minecraft account to your discord account. " +
+ .setDescription(MarkdownUtil.bold("This command will link your Minecraft account to your Discord account. " +
"Please use the following format:" +
System.lineSeparator() +
MarkdownUtil.codeblock("!verify ")) +