|
| 1 | +package io.greitan.mineserv.methods; |
| 2 | + |
| 3 | +import org.bukkit.Bukkit; |
| 4 | + |
| 5 | +import io.greitan.mineserv.MineservRewards; |
| 6 | + |
| 7 | +import java.sql.Connection; |
| 8 | +import java.sql.DriverManager; |
| 9 | +import java.sql.PreparedStatement; |
| 10 | +import java.sql.SQLException; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +import com.vexsoftware.votifier.model.Vote; |
| 14 | +import com.vexsoftware.votifier.VoteHandler; |
| 15 | +import com.vexsoftware.votifier.net.VotifierSession; |
| 16 | + |
| 17 | +public class Methods { |
| 18 | + private static MineservRewards plugin; |
| 19 | + |
| 20 | + public Methods(MineservRewards plugin) { |
| 21 | + Methods.plugin = plugin; |
| 22 | + } |
| 23 | + |
| 24 | + public static void runMethods(String project, String username, String timestamp, String signature) { |
| 25 | + // Проверка, включен ли NuVotifier в конфиге |
| 26 | + if (plugin.getConfig().getBoolean("config.methods.NuVotifier.enabled")) { |
| 27 | + votifier(project, username, timestamp, signature); |
| 28 | + } |
| 29 | + |
| 30 | + // Проверка, включен ли Commands в конфиге |
| 31 | + if (plugin.getConfig().getBoolean("config.methods.Commands.enabled")) { |
| 32 | + commands(project, username, timestamp, signature); |
| 33 | + } |
| 34 | + |
| 35 | + // Проверка, включен ли MySqlRequests в конфиге |
| 36 | + if (plugin.getConfig().getBoolean("config.methods.MySqlRequests.enabled")) { |
| 37 | + mysql(project, username, timestamp, signature); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + private static void votifier(String project, String username, String timestamp, String signature) { |
| 42 | + Vote vote = new Vote("mineserv.top", username, "mineserv.top", timestamp); |
| 43 | + VoteHandler voteHandler = plugin.getVoteHandler(); |
| 44 | + try { |
| 45 | + voteHandler.onVoteReceived(vote, VotifierSession.ProtocolVersion.UNKNOWN, "mineserv.top"); |
| 46 | + } catch (Exception e) { |
| 47 | + e.printStackTrace(); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + private static void commands(String project, String username, String timestamp, String signature) { |
| 52 | + List<String> commands = plugin.getConfig().getStringList("config.methods.Commands.commands"); |
| 53 | + executeCommands(commands, username); |
| 54 | + } |
| 55 | + |
| 56 | + private static void executeCommands(List<String> commands, String username) { |
| 57 | + for (String command : commands) { |
| 58 | + String processedCommand = command.replace("$player", username); |
| 59 | + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), processedCommand); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + private static void mysql(String project, String username, String timestamp, String signature) { |
| 64 | + String url = plugin.getConfig().getString("config.methods.MySqlRequests.url"); |
| 65 | + String database = plugin.getConfig().getString("config.methods.MySqlRequests.database"); |
| 66 | + String dbUsername = plugin.getConfig().getString("config.methods.MySqlRequests.username"); |
| 67 | + String dbPassword = plugin.getConfig().getString("config.methods.MySqlRequests.password"); |
| 68 | + |
| 69 | + List<String> sqlQueries = plugin.getConfig().getStringList("config.methods.MySqlRequests.sqlQuery"); |
| 70 | + |
| 71 | + try (Connection connection = DriverManager.getConnection(url + database, dbUsername, dbPassword)) { |
| 72 | + for (String sqlQuery : sqlQueries) { |
| 73 | + String processedQuery = sqlQuery.replace("$player", username); |
| 74 | + try (PreparedStatement preparedStatement = connection.prepareStatement(processedQuery)) { |
| 75 | + preparedStatement.executeUpdate(); |
| 76 | + } |
| 77 | + } |
| 78 | + } catch (SQLException e) { |
| 79 | + e.printStackTrace(); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments