Skip to content

Commit afcc34f

Browse files
committed
update
1 parent 09ef0f9 commit afcc34f

File tree

6 files changed

+123
-13
lines changed

6 files changed

+123
-13
lines changed

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ dependencies {
3030
compileOnly('io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT')
3131
compileOnly('me.clip:placeholderapi:2.11.5')
3232
compileOnly('org.projectlombok:lombok:1.18.30')
33-
compileOnly('com.github.nuvotifier.NuVotifier:nuvotifier-api:2.7.2')
3433
annotationProcessor('org.projectlombok:lombok:1.18.30')
3534

3635
implementation('com.fasterxml.jackson.core:jackson-databind:2.15.2')
3736
implementation('com.fasterxml.jackson.core:jackson-core:2.15.2')
37+
implementation('mysql:mysql-connector-java:8.0.33')
38+
39+
compileOnly "com.github.NuVotifier.NuVotifier:nuvotifier-api:2.7.2"
40+
compileOnly "com.github.NuVotifier.NuVotifier:nuvotifier-common:2.7.2"
41+
compileOnly "com.github.NuVotifier.NuVotifier:nuvotifier-bukkit:2.7.2"
3842
}
3943

4044
task deleteUnusableJar(type: Delete) {

nuvotifier.jar

2.73 MB
Binary file not shown.

src/main/java/io/greitan/mineserv/MineservRewards.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@
66
import org.bukkit.plugin.java.JavaPlugin;
77

88
import io.greitan.mineserv.commands.MineservCommand;
9+
import io.greitan.mineserv.methods.Methods;
910
import io.greitan.mineserv.network.Network;
1011
import io.greitan.mineserv.utils.*;
1112
import java.io.IOException;
12-
1313
import java.util.Objects;
1414

15+
import com.vexsoftware.votifier.VoteHandler;
16+
import com.vexsoftware.votifier.NuVotifierBukkit;
17+
import org.bukkit.Server;
18+
import org.bukkit.plugin.Plugin;
19+
import org.bukkit.plugin.PluginManager;
20+
1521
public class MineservRewards extends JavaPlugin {
1622
private static @Getter MineservRewards instance;
1723
private @Getter boolean isRunned = false;
1824
private @Getter String host = "";
1925
private @Getter int port = 0;
2026
private @Getter String secretKey = "";
27+
private @Getter VoteHandler VoteHandler;
2128

2229
private String lang;
2330

@@ -35,6 +42,8 @@ public void onEnable() {
3542
new Placeholder(this).register();
3643
}
3744

45+
new Methods(this);
46+
VoteHandler = getVoteHandler();
3847
this.reload();
3948
}
4049

@@ -68,4 +77,16 @@ public Boolean connect(String host, int port, String secretKey) {
6877
}
6978
} else return false;
7079
}
80+
81+
public NuVotifierBukkit createVoteHandler() {
82+
Server server = getServer();
83+
PluginManager pluginManager = server.getPluginManager();
84+
Plugin votifierPlugin = pluginManager.getPlugin("Votifier");
85+
86+
if (votifierPlugin instanceof NuVotifierBukkit) {
87+
return (NuVotifierBukkit) votifierPlugin;
88+
} else {
89+
return null;
90+
}
91+
}
7192
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
}

src/main/java/io/greitan/mineserv/network/Network.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
import java.net.InetSocketAddress;
1818
import java.net.URLDecoder;
1919

20-
import org.bukkit.Bukkit;
21-
20+
import io.greitan.mineserv.methods.Methods;
2221
import io.greitan.mineserv.utils.*;
2322

2423
public class Network {
@@ -64,7 +63,7 @@ public void handle(HttpExchange t) throws IOException {
6463
if (isSuccess) {
6564
response = "done";
6665
t.sendResponseHeaders(200, response.length());
67-
main(project, username, timestamp, signature);
66+
Methods.runMethods(project, username, timestamp, signature);
6867
} else {
6968
response = "error";
7069
t.sendResponseHeaders(500, response.length());
@@ -116,10 +115,6 @@ private static boolean checkSign(String project, String username, String timesta
116115
}
117116
}
118117

119-
private static void main(String project, String username, String timestamp, String signature) {
120-
Bukkit.getLogger().info(project + username + timestamp + signature);
121-
}
122-
123118
private static Map<String, String> parse(String queryString) {
124119
Map<String, String> parameters = new HashMap<>();
125120

src/main/resources/config.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@ config:
22
debug: false
33

44
host: "0.0.0.0"
5-
port: 80
5+
port: 9999
66
secret-key: "key"
77

88
methods:
99
NuVotifier:
1010
enabled: false
11-
СommandRun:
11+
Commands:
1212
enabled: false
13-
commands: []
13+
commands: [
14+
"give $player diamond 20"
15+
]
1416
MySqlRequests:
17+
enabled: false
18+
url: "jdbc:mysql://localhost:3306/"
19+
1520
database: "mineserv"
1621
username: "mineserv"
1722
password: "mineserv"
18-
sqlQuery: []
23+
24+
sqlQuery: [
25+
"UPDATE `iconomy` SET `balance`=`balance`+100 WHERE `username`='$player'"
26+
]

0 commit comments

Comments
 (0)