Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Pequla committed Apr 16, 2021
1 parent 8997480 commit 8972c5e
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 45 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.samifying</groupId>
<artifactId>main-plugin</artifactId>
<version>1.1</version>
<version>1.2</version>
<packaging>jar</packaging>

<name>MainPlugin</name>
Expand Down Expand Up @@ -91,11 +91,6 @@
<artifactId>spark-core</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
Expand All @@ -112,5 +107,10 @@
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
15 changes: 1 addition & 14 deletions src/main/java/com/samifying/plugin/DatabaseAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.sql.*;
import java.time.Instant;

public class DatabaseAccess {

Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/samifying/plugin/MainPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/com/samifying/plugin/events/PlayerLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/samifying/plugin/modules/CommandModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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 <your-minecraft-username>")) +
Expand Down

0 comments on commit 8972c5e

Please sign in to comment.