Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
55f7cabd26 | |||
05c0199eb2 | |||
![]() |
b3e26fa1c2 | ||
![]() |
d0635b57e7 | ||
c0fc86c812 | |||
522cdee07f |
@ -30,7 +30,7 @@ vote: # Награда за голос
|
||||
# Каждый параметр наград не обязателен, но не должен использоваться больше 1 раза
|
||||
# Указывать предмет вот так: "{название_предмета} {кол_во}"
|
||||
|
||||
add_comment: # Награда за удаление отзыва
|
||||
add_comment: # Награда за добавление отзыва
|
||||
vault: 10
|
||||
message: "Спасибо за отзыв!"
|
||||
# Тут могут использоваться все параметры из наград за голоса
|
||||
|
30
pom.xml
30
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>ru.froggymonitor</groupId>
|
||||
<artifactId>rewardplugin</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<version>1.4.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>FroggyMonitorReward</name>
|
||||
@ -89,16 +89,14 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.16.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.5</version>
|
||||
<scope>provided</scope>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.16.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
@ -111,14 +109,16 @@
|
||||
<version>4.16.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.16.0</version>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.16.0</version>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -9,13 +9,15 @@ import org.bukkit.block.data.type.TripwireHook;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
@ -198,14 +200,34 @@ public final class Main extends JavaPlugin implements Listener {
|
||||
"\"comment_url\": \""+start_url+comment_page+"\"}";
|
||||
|
||||
try {
|
||||
httpClient.send(HttpRequest.newBuilder()
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.uri(URI.create("https://froggymonitor.ru/api/set_reward_urls"))
|
||||
.build(), HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
URL url = new URL("http://froggymonitor.ru/api/set_reward_urls");
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("Content-Length", Integer.toString(body.getBytes().length));
|
||||
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoOutput(true);
|
||||
|
||||
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
||||
wr.writeBytes(body);
|
||||
wr.close();
|
||||
|
||||
InputStream is = connection.getInputStream();
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder response = new StringBuilder();
|
||||
String line;
|
||||
|
||||
while ((line = rd.readLine()) != null) {
|
||||
response.append(line);
|
||||
response.append('\r');
|
||||
}
|
||||
rd.close();
|
||||
|
||||
connection.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
package ru.froggymonitor.rewardplugin;
|
||||
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
public enum MessageFormatting {
|
||||
AMPERSAND("ampersand", (str) -> LegacyComponentSerializer.legacyAmpersand().deserialize(str)),
|
||||
SECTION("section", (str) -> LegacyComponentSerializer.legacySection().deserialize(str)),
|
||||
MINIMESSAGE("minimessage", (str) -> (TextComponent) MiniMessage.miniMessage().deserialize(str)),
|
||||
JSON("json", (str) -> (TextComponent) JSONComponentSerializer.json().deserialize(str));
|
||||
AMPERSAND("ampersand", (str) -> TextComponent.fromLegacyText(str.replace("&", "§"))),
|
||||
SECTION("section", (str) -> TextComponent.fromLegacyText(str)),
|
||||
MINIMESSAGE("minimessage", (str) -> kyoriToBungee((net.kyori.adventure.text.TextComponent) MiniMessage.miniMessage().deserialize(str))),
|
||||
JSON("json", (str) -> ComponentSerializer.parse(str));
|
||||
|
||||
public interface MessageFormat {
|
||||
TextComponent format(String input);
|
||||
BaseComponent[] format(String input);
|
||||
}
|
||||
|
||||
private MessageFormat format_func;
|
||||
@ -29,7 +29,7 @@ public enum MessageFormatting {
|
||||
}
|
||||
|
||||
public BaseComponent[] format(String str) {
|
||||
return ComponentSerializer.parse(JSONComponentSerializer.json().serialize(format_func.format(str)));
|
||||
return format_func.format(str);
|
||||
}
|
||||
|
||||
public static MessageFormatting getFormatting(String name) {
|
||||
@ -40,4 +40,12 @@ public enum MessageFormatting {
|
||||
}
|
||||
return SECTION;
|
||||
}
|
||||
|
||||
public static BaseComponent[] kyoriToBungee(net.kyori.adventure.text.TextComponent text) {
|
||||
return ComponentSerializer.parse(JSONComponentSerializer.json().serialize(text));
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.TextComponent bungeeToKyori(BaseComponent[] text) {
|
||||
return (net.kyori.adventure.text.TextComponent) JSONComponentSerializer.json().deserialize(ComponentSerializer.toString(text));
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class ReloadCommand implements CommandExecutor, TabCompleter {
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
Main.me.onJoin(new PlayerJoinEvent(p, ""));
|
||||
|
||||
sender.sendMessage("Перезагрузка успешно завершена");
|
||||
sender.sendMessage("Плагин успешно перезагружен");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
StringWriter buffer = new StringWriter();
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -23,6 +24,8 @@ public class Reward {
|
||||
}
|
||||
|
||||
public void execute(String nickname) {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
Player player = Bukkit.getPlayer(nickname);
|
||||
|
||||
if (player != null) {
|
||||
@ -35,31 +38,53 @@ public class Reward {
|
||||
|
||||
if (offlinePlayer != null) {
|
||||
if (data.containsKey("vault")) {
|
||||
try {
|
||||
Main.me.giveVault(offlinePlayer,
|
||||
((Number) data.get("vault")).doubleValue());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (data.containsKey("commands")) {
|
||||
try {
|
||||
for (String c : new ArrayList<>((List<String>) data.get("commands"))) {
|
||||
if (c.startsWith("/")) c = c.substring(1);
|
||||
getServer().dispatchCommand(getServer().getConsoleSender(),PlaceholderAPI.setPlaceholders(offlinePlayer, c));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTask(Main.me);
|
||||
}
|
||||
|
||||
public void later(Player player) {
|
||||
if (data.containsKey("item")) {
|
||||
try {
|
||||
String[] ss = ((String)data.get("item")).split(" ");
|
||||
ItemStack item = new ItemStack(Material.valueOf(ss[0].toUpperCase()), ss.length == 1 ? 1 : Integer.parseInt(ss[1]));
|
||||
player.getInventory().addItem(item);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (data.containsKey("message")) {
|
||||
try {
|
||||
player.spigot().sendMessage(Main.me.formatMessage(player, (String) data.get("message")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (data.containsKey("as_player")) {
|
||||
try {
|
||||
for (String c : new ArrayList<>((List<String>) data.get("as_player"))) {
|
||||
player.chat(c);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,24 @@ import com.google.common.base.Charsets;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.bukkit.Bukkit.getServer;
|
||||
|
||||
public class SitePart extends FormDataHandler {
|
||||
public HttpServer server;
|
||||
|
||||
@ -51,6 +63,7 @@ public class SitePart extends FormDataHandler {
|
||||
String method = e.getRequestMethod();
|
||||
String path = e.getRequestURI().getPath();
|
||||
|
||||
try {
|
||||
if (method.equals("GET")) {
|
||||
if (path.equals(Main.me.vote_page)) {
|
||||
if (params.containsKey("nickname") &&
|
||||
@ -60,7 +73,9 @@ public class SitePart extends FormDataHandler {
|
||||
String timestamp = (String) params.get("timestamp");
|
||||
String secret = (String) params.get("secret");
|
||||
|
||||
if (sha256(nickname + timestamp + Main.me.secret_token).equals(secret)) {
|
||||
String secret_gen = sha256(nickname + timestamp + Main.me.secret_token);
|
||||
|
||||
if (secret_gen.equals(secret)) {
|
||||
Main.me.vote_reward.execute(nickname);
|
||||
response = "ok";
|
||||
status_code = 200;
|
||||
@ -80,7 +95,9 @@ public class SitePart extends FormDataHandler {
|
||||
String timestamp = (String) params.get("timestamp");
|
||||
String secret = (String) params.get("secret");
|
||||
|
||||
if (sha256(username + nickname + timestamp + Main.me.secret_token).equals(secret)) {
|
||||
String secret_gen = sha256(username + nickname + timestamp + Main.me.secret_token);
|
||||
|
||||
if (secret_gen.equals(secret)) {
|
||||
if (type.equals("insert")) {
|
||||
Main.me.add_comment_reward.execute(nickname);
|
||||
|
||||
@ -101,12 +118,11 @@ public class SitePart extends FormDataHandler {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
e.sendResponseHeaders(status_code, response.length());
|
||||
|
||||
OutputStream os = e.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
} catch (IOException ex) {
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ vote: # Награда за голос
|
||||
# Каждый параметр наград не обязателен, но не должен использоваться больше 1 раза
|
||||
# Указывать предмет вот так: "{название_предмета} {кол_во}"
|
||||
|
||||
add_comment: # Награда за удаление отзыва
|
||||
add_comment: # Награда за добавление отзыва
|
||||
vault: 10
|
||||
message: "Спасибо за отзыв!"
|
||||
# Тут могут использоваться все параметры из наград за голоса
|
||||
|
Loading…
Reference in New Issue
Block a user