license
This commit is contained in:
parent
7f5981d435
commit
23349618ff
13
LICENSE
13
LICENSE
@ -0,0 +1,13 @@
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
41
README.md
41
README.md
@ -1,2 +1,43 @@
|
||||
# FroggyMonitorReward
|
||||
Плагин для награды игроков за голоса и отзывы на FroggyMonitor
|
||||
|
||||
Плагин запускает сайт,
|
||||
на который будут приходить запросы от
|
||||
FroggyMonitor на поощрение игрока,
|
||||
плагин их читает и выполняет действие из конфига
|
||||
|
||||
## Конфиг
|
||||
```yml
|
||||
site_host: localhost # IP адрес для сайта
|
||||
site_port: 8080 # Порт для сайта
|
||||
site_backlog: 5 # Максимальное кол-во подключений одновременно
|
||||
|
||||
secret_token: "ваш_секретный_токен" # Секретный токен с FroggyMonitor
|
||||
|
||||
comment_page: "/api/comment" # Страница для награды за отзыв
|
||||
vote_page: "/api/vote" # Страница для награды за голос
|
||||
|
||||
# Что указать в FroggyMonitor?
|
||||
# В URL для поощрения за отзыв:
|
||||
# http://{ip_сервера}:{site_port}{comment_page}
|
||||
# -> http://example.com:8080/api/comment
|
||||
# В URL для поощрения за голос:
|
||||
# http://{ip_сервера}:{site_port}{vote_page}
|
||||
# -> http://example.com:8080/api/vote
|
||||
# Также возможно понадобится открыть порт на хосте
|
||||
|
||||
vote: # Награда за голос
|
||||
vault: 10 # Выдать валюту (необяз.)
|
||||
item: "diamond 10" # Выдать предмет (необяз.) (забрать предмет нельзя)
|
||||
message: "Спасибо за голос!" # Отправить сообщение (необяз.)
|
||||
commands: # Исполнить команды (необяз.)
|
||||
- "/title {player_name} subtitle на FroggyMonitor"
|
||||
- "/title {player_name} title Спасибо за отзыв!"
|
||||
|
||||
add_comment: # Награда за удаление отзыва
|
||||
vault: 10
|
||||
message: "Спасибо за отзыв!"
|
||||
|
||||
del_comment: # Награда за удаление отзыва
|
||||
vault: -10 # Снять валюту
|
||||
```
|
33
pom.xml
33
pom.xml
@ -4,14 +4,14 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>themixray</groupId>
|
||||
<artifactId>monitoring-reward</artifactId>
|
||||
<groupId>ru.froggymonitor</groupId>
|
||||
<artifactId>rewardplugin</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Monitoring Reward</name>
|
||||
<name>FroggyMonitorReward</name>
|
||||
|
||||
<description>Monitoring Rewards</description>
|
||||
<description>Плагин для награды игроков за голоса и отзывы на FroggyMonitor</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@ -76,13 +76,8 @@
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>enginehub-maven</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@ -90,7 +85,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20.1-R0.1-SNAPSHOT</version>
|
||||
<version>1.13.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -100,16 +95,10 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ssomar.score</groupId>
|
||||
<artifactId>SCore</artifactId>
|
||||
<version>4.24.2.14</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/src/main/resources/SCore.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api-plugin</artifactId>
|
||||
<version>2.12.0</version>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,4 +1,4 @@
|
||||
package themixray.monitoringreward;
|
||||
package ru.froggymonitor.rewardplugin;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.sun.net.httpserver.Headers;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package themixray.monitoringreward;
|
||||
package ru.froggymonitor.rewardplugin;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -29,200 +28,8 @@ public final class Main extends JavaPlugin implements Listener {
|
||||
|
||||
public SitePart site;
|
||||
public Economy econ;
|
||||
public Random rand;
|
||||
|
||||
public FileConfiguration file;
|
||||
|
||||
public Map<String,Map<String,Integer>> cache;
|
||||
public ConfigReader cache_conf;
|
||||
public FileConfiguration cache_file;
|
||||
|
||||
public String hotmc_token;
|
||||
public String mineserv_token;
|
||||
public String minecraftrating_token;
|
||||
public String misterlauncher_token;
|
||||
|
||||
public String site_ip;
|
||||
public int site_port;
|
||||
|
||||
public Map<String,String> reward_messages;
|
||||
public Map<String,String> super_reward_messages;
|
||||
public int super_reward_votes;
|
||||
public int spec_super_reward_votes;
|
||||
|
||||
public boolean player_offline_only_money;
|
||||
public boolean add_vote_command;
|
||||
public boolean add_general_monitoring;
|
||||
public boolean add_specific_monitoring;
|
||||
|
||||
public List<Map<String,Object>> super_reward;
|
||||
public List<Map<String,Object>> spec_super_reward;
|
||||
public List<Map<String,Object>> default_reward;
|
||||
|
||||
public Map<String,Map<String,Object>> reward_when_join;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (!setupEconomy()) {
|
||||
getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
me = this;
|
||||
|
||||
new ReloadCommand(this);
|
||||
|
||||
rand = new Random();
|
||||
|
||||
reward_when_join = new HashMap<>();
|
||||
|
||||
saveDefaultConfig();
|
||||
file = getConfig();
|
||||
|
||||
cache = new HashMap<>();
|
||||
|
||||
File f = Path.of(getDataFolder().getPath(),"cache.yml").toFile();
|
||||
if (!f.exists()) {
|
||||
try {
|
||||
f.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
cache_conf = new ConfigReader(this,"./","cache.yml");
|
||||
cache_file = cache_conf.getConfig();
|
||||
|
||||
Map<String,Object> players_sect = cache_file.getValues(false);
|
||||
for (Map.Entry<String,Object> p:players_sect.entrySet()) {
|
||||
Map<String,Object> monitoring_sect = ((MemorySection)p.getValue()).getValues(false);
|
||||
Map<String,Integer> monitoring = new HashMap<>();
|
||||
for (Map.Entry<String,Object> m:monitoring_sect.entrySet())
|
||||
monitoring.put(m.getKey(),(Integer)m.getValue());
|
||||
cache.put(p.getKey(),monitoring);
|
||||
}
|
||||
|
||||
site_ip = file.getString("site_ip");
|
||||
site_port = file.getInt("site_port");
|
||||
|
||||
hotmc_token = file.getString("hotmc_token");
|
||||
minecraftrating_token = file.getString("minecraftrating_token");
|
||||
misterlauncher_token = file.getString("misterlauncher_token");
|
||||
mineserv_token = file.getString("mineserv_token");
|
||||
|
||||
reward_messages = new HashMap<>();
|
||||
Map<String,Object> reward_message_sect = ((MemorySection)file.get("reward_message")).getValues(false);
|
||||
for (Map.Entry<String,Object> e:reward_message_sect.entrySet())
|
||||
reward_messages.put(e.getKey(),translateHexCodes((String) e.getValue()));
|
||||
|
||||
super_reward_messages = new HashMap<>();
|
||||
Map<String,Object> super_reward_message_sect = ((MemorySection)file.get("super_reward_message")).getValues(false);
|
||||
for (Map.Entry<String,Object> e:super_reward_message_sect.entrySet())
|
||||
super_reward_messages.put(e.getKey(),translateHexCodes((String) e.getValue()));
|
||||
|
||||
player_offline_only_money = file.getBoolean("player_offline_only_money");
|
||||
add_vote_command = file.getBoolean("add_vote_command");
|
||||
add_general_monitoring = file.getBoolean("add_general_monitoring");
|
||||
add_specific_monitoring = file.getBoolean("add_specific_monitoring");
|
||||
super_reward_votes = file.getInt("super_reward_votes");
|
||||
super_reward = new ArrayList<>();
|
||||
List<Map<?, ?>> super_reward_sect = file.getMapList("super_reward");
|
||||
for (Map<?, ?> e:super_reward_sect) {
|
||||
Map<String, Object> i = (Map<String, Object>) e;
|
||||
Map<String, Object> o = new HashMap<>();
|
||||
|
||||
String type = (String) i.get("type");
|
||||
if (type.equals("item")) {
|
||||
o.put("name", i.get("name"));
|
||||
o.put("item", ItemsParser.parseItem((Map<String, Object>) i.get("item")));
|
||||
} else if (type.equals("money")) {
|
||||
o.put("count", i.get("count"));
|
||||
}
|
||||
o.put("type", i.get("type"));
|
||||
super_reward.add(o);
|
||||
}
|
||||
spec_super_reward_votes = file.getInt("special_super_reward_votes");
|
||||
spec_super_reward = new ArrayList<>();
|
||||
List<Map<?, ?>> spec_super_reward_sect = file.getMapList("special_super_reward");
|
||||
for (Map<?, ?> e:spec_super_reward_sect) {
|
||||
Map<String, Object> i = (Map<String, Object>) e;
|
||||
Map<String, Object> o = new HashMap<>();
|
||||
|
||||
String type = (String) i.get("type");
|
||||
if (type.equals("item")) {
|
||||
o.put("name", i.get("name"));
|
||||
o.put("item", ItemsParser.parseItem((Map<String, Object>) i.get("item")));
|
||||
} else if (type.equals("money")) {
|
||||
o.put("count", i.get("count"));
|
||||
}
|
||||
o.put("type", i.get("type"));
|
||||
spec_super_reward.add(o);
|
||||
}
|
||||
default_reward = new ArrayList<>();
|
||||
List<Map<?, ?>> default_reward_sect = file.getMapList("default_reward");
|
||||
for (Map<?, ?> e:default_reward_sect) {
|
||||
Map<String, Object> i = (Map<String, Object>) e;
|
||||
Map<String, Object> o = new HashMap<>();
|
||||
|
||||
String type = (String) i.get("type");
|
||||
if (type.equals("item")) {
|
||||
o.put("name", i.get("name"));
|
||||
o.put("item", ItemsParser.parseItem((Map<String, Object>) i.get("item")));
|
||||
} else if (type.equals("money")) {
|
||||
o.put("count", i.get("count"));
|
||||
}
|
||||
o.put("type", i.get("type"));
|
||||
default_reward.add(o);
|
||||
}
|
||||
|
||||
site = new SitePart(site_ip,site_port);
|
||||
getLogger().info("Server "+site_ip+":"+site_port+" started!");
|
||||
|
||||
getServer().getPluginManager().registerEvents(this,this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
site.server.stop(0);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
String player = e.getPlayer().getName();
|
||||
if (reward_when_join.containsKey(player)) {
|
||||
Map<String,Object> r = reward_when_join.get(player);
|
||||
String type = (String) r.get("type");
|
||||
if (type.equals("item")) {
|
||||
ItemStack item = (ItemStack) r.get("item");
|
||||
String name = (String) r.get("name");
|
||||
p.getInventory().addItem(item);
|
||||
String rm = (String) r.get("message");
|
||||
if (rm.contains("%d")) {
|
||||
p.sendMessage(String.format(rm,name,
|
||||
getVotesBeforeSuper(player)));
|
||||
} else {
|
||||
p.sendMessage(String.format(rm,name));
|
||||
}
|
||||
}
|
||||
reward_when_join.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommand(PlayerCommandPreprocessEvent e) {
|
||||
if (add_vote_command) {
|
||||
String cmd = e.getMessage().split(" ")[0];
|
||||
if (cmd.startsWith("/")) cmd = cmd.substring(1);
|
||||
|
||||
if (cmd.startsWith("vote")) {
|
||||
String monitoring = cmd.split("/")[1];
|
||||
sendVote(e.getPlayer().getName(), monitoring);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
public UnrealConfig conf;
|
||||
|
||||
private boolean setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
@ -236,94 +43,58 @@ public final class Main extends JavaPlugin implements Listener {
|
||||
return econ != null;
|
||||
}
|
||||
|
||||
public void sendVote(String player, String monitoring) {
|
||||
getLogger().info(player+" voted on "+monitoring);
|
||||
if (add_general_monitoring) addVoteGeneral(player,monitoring);
|
||||
if (add_specific_monitoring) addVote(player,monitoring);
|
||||
public String secret_token;
|
||||
|
||||
public String comment_page;
|
||||
public String vote_page;
|
||||
|
||||
public Reward vote_reward;
|
||||
public Reward add_comment_reward;
|
||||
public Reward del_comment_reward;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (!setupEconomy()) {
|
||||
getLogger().severe("[FroggyMonitorReward] - Disabled due to no Vault dependency found!");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
public void addVote(String player, String monitoring) {
|
||||
if (cache.containsKey(player)) {
|
||||
cache.get(player).put(monitoring,
|
||||
cache.get(player).getOrDefault(
|
||||
monitoring,0)+1);
|
||||
} else {
|
||||
Map<String,Integer> m = new HashMap<>();
|
||||
m.put(monitoring,1);
|
||||
cache.put(player,m);
|
||||
}
|
||||
if (cache.get(player).get(monitoring) >= spec_super_reward_votes) {
|
||||
giveReward(player, spec_super_reward, super_reward_messages.get(monitoring));
|
||||
cache.get(player).put(monitoring, 0);
|
||||
}
|
||||
saveCache();
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") == null) {
|
||||
getLogger().severe("[FroggyMonitorReward] - Disabled due to no PlaceholderAPI dependency found!");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
public void addVoteGeneral(String player, String monitoring) {
|
||||
if (cache.containsKey(player)) {
|
||||
cache.get(player).put("general",
|
||||
cache.get(player).getOrDefault(
|
||||
"general",0)+1);
|
||||
} else {
|
||||
Map<String,Integer> m = new HashMap<>();
|
||||
m.put("general",1);
|
||||
cache.put(player,m);
|
||||
}
|
||||
if (cache.get(player).get("general") >= super_reward_votes) {
|
||||
giveReward(player, super_reward, super_reward_messages.get("general"));
|
||||
cache.get(player).put("general", 0);
|
||||
} else {
|
||||
giveReward(player, default_reward, reward_messages.get(monitoring));
|
||||
}
|
||||
saveCache();
|
||||
me = this;
|
||||
|
||||
conf = new UnrealConfig(this, "config.yml");
|
||||
|
||||
secret_token = (String) conf.get("secret_token");
|
||||
|
||||
comment_page = (String) conf.get("comment_page");
|
||||
vote_page = (String) conf.get("vote_page");
|
||||
|
||||
vote_reward = new Reward((Map<String, Object>) conf.get("vote"));
|
||||
add_comment_reward = new Reward((Map<String, Object>) conf.get("add_comment"));
|
||||
del_comment_reward = new Reward((Map<String, Object>) conf.get("del_comment"));
|
||||
|
||||
site = new SitePart(
|
||||
(String) conf.get("site_host"),
|
||||
((Number) conf.get("site_port")).intValue(),
|
||||
((Number) conf.get("site_backlog")).intValue());
|
||||
|
||||
site.start();
|
||||
|
||||
getServer().getPluginManager().registerEvents(this,this);
|
||||
}
|
||||
|
||||
public int getVotesBeforeSuper(String player) {
|
||||
return super_reward_votes-cache.get(player).getOrDefault("general",0);
|
||||
@Override
|
||||
public void onDisable() {
|
||||
site.stop();
|
||||
}
|
||||
|
||||
public void giveReward(String player, List<Map<String,Object>> rewards, String message) {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
if (player_offline_only_money && p == null) {
|
||||
while (true) {
|
||||
int index = rand.nextInt(0, rewards.size());
|
||||
Map<String, Object> r = rewards.get(index);
|
||||
String type = (String) r.get("type");
|
||||
if (!type.equals("money")) continue;
|
||||
econ.depositPlayer(getOfflinePlayer(player), (int) r.get("count"));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
int index = rand.nextInt(0, rewards.size());
|
||||
Map<String, Object> r = rewards.get(index);
|
||||
String type = (String) r.get("type");
|
||||
String name = null;
|
||||
if (type.equals("item")) {
|
||||
ItemStack item = (ItemStack) r.get("item");
|
||||
name = (String) r.get("name");
|
||||
if (p != null) p.getInventory().addItem(item);
|
||||
else {
|
||||
Map<String, Object> t = new HashMap<>(r);
|
||||
t.put("message", message);
|
||||
reward_when_join.put(player,t);
|
||||
}
|
||||
} else if (type.equals("money")) {
|
||||
int count = (int) r.get("count");
|
||||
econ.depositPlayer(getOfflinePlayer(player),count);
|
||||
name = econ.format(count);
|
||||
}
|
||||
if (p != null) {
|
||||
if (message.contains("%d")) {
|
||||
p.sendMessage(String.format(message,name,
|
||||
getVotesBeforeSuper(player)));
|
||||
} else {
|
||||
p.sendMessage(String.format(message,name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public OfflinePlayer getOfflinePlayer(String name) {
|
||||
public static OfflinePlayer getOfflinePlayer(String name) {
|
||||
for (OfflinePlayer p:Bukkit.getOfflinePlayers()) {
|
||||
if (p.getName().equals(name)) {
|
||||
return p;
|
||||
@ -331,19 +102,4 @@ public final class Main extends JavaPlugin implements Listener {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void saveCache() {
|
||||
for (Map.Entry<String,Map<String,Integer>> e:cache.entrySet())
|
||||
cache_file.set(e.getKey(),e.getValue());
|
||||
cache_conf.saveConfig();
|
||||
}
|
||||
|
||||
public static final Pattern HEX_PATTERN = Pattern.compile("&#(\\w{5}[0-9a-f])");
|
||||
|
||||
public String translateHexCodes(String textToTranslate) {
|
||||
Matcher matcher = HEX_PATTERN.matcher(textToTranslate);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
while (matcher.find()) matcher.appendReplacement(buffer, ChatColor.of("#" + matcher.group(1)).toString());
|
||||
return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString());
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,52 @@
|
||||
package ru.froggymonitor.rewardplugin;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.bukkit.Bukkit.getServer;
|
||||
|
||||
public class Reward {
|
||||
public Map<String,Object> data;
|
||||
|
||||
public Reward(Map<String,Object> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void execute(String nickname) {
|
||||
Player player = Bukkit.getPlayer(nickname);
|
||||
|
||||
if (player != null) {
|
||||
if (data.containsKey("item")) {
|
||||
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);
|
||||
}
|
||||
if (data.containsKey("message")) {
|
||||
player.sendMessage(PlaceholderAPI.setPlaceholders(player, (String) data.get("message")));
|
||||
}
|
||||
}
|
||||
|
||||
OfflinePlayer offlinePlayer = Main.getOfflinePlayer(nickname);
|
||||
|
||||
if (offlinePlayer != null) {
|
||||
if (data.containsKey("vault")) {
|
||||
Main.me.econ.depositPlayer(offlinePlayer,
|
||||
((Number) data.get("vault")).doubleValue());
|
||||
}
|
||||
if (data.containsKey("commands")) {
|
||||
for (String c : new ArrayList<>((List<String>) data.get("commands"))) {
|
||||
if (c.startsWith("/")) c = c.substring(1);
|
||||
getServer().dispatchCommand(getServer().getConsoleSender(),c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package themixray.monitoringreward;
|
||||
package ru.froggymonitor.rewardplugin;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.hash.Hashing;
|
||||
@ -17,20 +17,24 @@ import java.util.Map;
|
||||
public class SitePart extends FormDataHandler {
|
||||
public HttpServer server;
|
||||
|
||||
public SitePart(String host, int port) {
|
||||
public SitePart(String host, int port, int backlog) {
|
||||
try {
|
||||
server = HttpServer.create(new InetSocketAddress(host,port),0);
|
||||
server.createContext("/vote",this);
|
||||
server = HttpServer.create(new InetSocketAddress(host,port),backlog);
|
||||
server.createContext("/",this);
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String sha1(String s) {
|
||||
return Hashing.sha1().hashString(s, Charsets.UTF_8).toString();
|
||||
public void start() {
|
||||
server.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
server.stop(1);
|
||||
}
|
||||
|
||||
public String sha256(String s) {
|
||||
return Hashing.sha256().hashString(s, Charsets.UTF_8).toString();
|
||||
}
|
||||
@ -43,76 +47,44 @@ public class SitePart extends FormDataHandler {
|
||||
String method = e.getRequestMethod();
|
||||
String path = e.getRequestURI().getPath();
|
||||
|
||||
if (method.equals("POST")) {
|
||||
if (path.equals("/vote/hotmc")) {
|
||||
if (params.size() == 3) {
|
||||
if (params.containsKey("nick") &&
|
||||
params.containsKey("time") &&
|
||||
params.containsKey("sign")) {
|
||||
String nick = (String) params.get("nick");
|
||||
String time = (String) params.get("time");
|
||||
String sign = (String) params.get("sign");
|
||||
String sign_gen = sha1(nick+time+Main.me.hotmc_token);
|
||||
if (method.equals("GET")) {
|
||||
if (path.equals(Main.me.vote_page)) {
|
||||
if (params.containsKey("nickname") &&
|
||||
params.containsKey("timestamp") &&
|
||||
params.containsKey("secret")) {
|
||||
String nickname = (String) params.get("nickname");
|
||||
String timestamp = (String) params.get("timestamp");
|
||||
String secret = (String) params.get("secret");
|
||||
|
||||
if (sign.equals(sign_gen)) {
|
||||
if (sha256(nickname + timestamp + Main.me.secret_token).equals(secret)) {
|
||||
Main.me.vote_reward.execute(nickname);
|
||||
response = "ok";
|
||||
status_code = 200;
|
||||
Main.me.sendVote(nick,"hotmc");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (path.equals("/vote/mineserv")) {
|
||||
if (params.size() == 4) {
|
||||
if (params.containsKey("project") &&
|
||||
} else if (path.equals(Main.me.comment_page)) {
|
||||
if (params.containsKey("nickname") &&
|
||||
params.containsKey("type") &&
|
||||
params.containsKey("username") &&
|
||||
params.containsKey("timestamp") &&
|
||||
params.containsKey("signature")) {
|
||||
String project = (String) params.get("project");
|
||||
params.containsKey("secret")) {
|
||||
String type = (String) params.get("type");
|
||||
String username = (String) params.get("username");
|
||||
String nickname = (String) params.get("nickname");
|
||||
String timestamp = (String) params.get("timestamp");
|
||||
String signature = (String) params.get("signature");
|
||||
String sign_gen = sha256(project+"."+Main.me.mineserv_token+"."+timestamp+"."+username);
|
||||
String secret = (String) params.get("secret");
|
||||
|
||||
if (signature.equals(sign_gen)) {
|
||||
response = "done";
|
||||
status_code = 200;
|
||||
Main.me.sendVote(username,"mineserv");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (path.equals("/vote/minecraftrating")) {
|
||||
if (params.size() == 4) {
|
||||
if (params.containsKey("ip") &&
|
||||
params.containsKey("username") &&
|
||||
params.containsKey("timestamp") &&
|
||||
params.containsKey("signature")) {
|
||||
String username = (String) params.get("username");
|
||||
String timestamp = (String) params.get("timestamp");
|
||||
String signature = (String) params.get("signature");
|
||||
String sign_gen = sha1(username+timestamp+Main.me.minecraftrating_token);
|
||||
if (sha256(username + nickname + timestamp + Main.me.secret_token).equals(secret)) {
|
||||
if (type.equals("insert")) {
|
||||
Main.me.add_comment_reward.execute(nickname);
|
||||
|
||||
if (signature.equals(sign_gen)) {
|
||||
response = "ok";
|
||||
status_code = 200;
|
||||
Main.me.sendVote(username,"minecraftrating");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (path.equals("/vote/misterlauncher")) {
|
||||
if (params.size() == 4) {
|
||||
if (params.containsKey("ip") &&
|
||||
params.containsKey("username") &&
|
||||
params.containsKey("timestamp") &&
|
||||
params.containsKey("signature")) {
|
||||
String username = (String) params.get("username");
|
||||
String timestamp = (String) params.get("timestamp");
|
||||
String signature = (String) params.get("signature");
|
||||
String sign_gen = sha1(username+timestamp+Main.me.misterlauncher_token);
|
||||
} else if (type.equals("delete")) {
|
||||
Main.me.del_comment_reward.execute(nickname);
|
||||
|
||||
if (signature.equals(sign_gen)) {
|
||||
response = "ok";
|
||||
status_code = 200;
|
||||
Main.me.sendVote(username,"misterlauncher");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package themixray.mainplugin.util;
|
||||
package ru.froggymonitor.rewardplugin;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -10,54 +10,21 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class UnrealConfig extends HashMap<String, Object> {
|
||||
private static final Yaml yaml = new Yaml();
|
||||
|
||||
private Yaml yaml;
|
||||
private File file;
|
||||
|
||||
public static UnrealConfig getByFileOrDefault(File file, Map<String,Object> def) {
|
||||
return new UnrealConfig(file,def);
|
||||
}
|
||||
|
||||
public static UnrealConfig getByFileOrDefault(File file, Runnable on_def) {
|
||||
return new UnrealConfig(file,on_def);
|
||||
}
|
||||
|
||||
public static UnrealConfig getByResource(JavaPlugin plugin, String resource) {
|
||||
return new UnrealConfig(plugin,resource);
|
||||
}
|
||||
|
||||
public static UnrealConfig getByFile(JavaPlugin plugin, String file) {
|
||||
return new UnrealConfig(plugin, file);
|
||||
}
|
||||
|
||||
public static UnrealConfig getByFile(File file) {
|
||||
return new UnrealConfig(file,new HashMap<>());
|
||||
}
|
||||
|
||||
private UnrealConfig(File file, Map<String,Object> def) {
|
||||
this.file = file;
|
||||
if (file.exists()) {
|
||||
reload();
|
||||
} else {
|
||||
file.mkdirs();
|
||||
putAll(def);
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
private UnrealConfig(File file, Runnable on_def) {
|
||||
this.file = file;
|
||||
if (!file.exists()) on_def.run();
|
||||
reload();
|
||||
}
|
||||
|
||||
private UnrealConfig(JavaPlugin plugin, String filename) {
|
||||
public UnrealConfig(JavaPlugin plugin, String filename) {
|
||||
file = Paths.get(plugin.getDataFolder().getPath(),filename).toFile();
|
||||
if (!file.exists()) plugin.saveResource(filename,false);
|
||||
reload();
|
||||
yaml = new Yaml();
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
try {
|
||||
clear();
|
||||
putAll(yaml.load(new FileInputStream(file)));
|
||||
@ -66,7 +33,7 @@ public class UnrealConfig extends HashMap<String, Object> {
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
public void saveConfig() {
|
||||
try {
|
||||
yaml.dump(this,new FileWriter(file, Charsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
|
@ -1,101 +1,28 @@
|
||||
site_ip: localhost # IP адрес для сайта
|
||||
site_host: localhost # IP адрес для сайта
|
||||
site_port: 8080 # Порт для сайта
|
||||
site_backlog: 5 # Максимальное кол-во подключений одновременно
|
||||
|
||||
add_vote_command: false # Тестовая команда /vote/мониторинг
|
||||
secret_token: "ваш_секретный_токен" # Секретный токен с FroggyMonitor
|
||||
|
||||
add_general_monitoring: true # Добавлять голос к общему счетчику
|
||||
add_specific_monitoring: true # Добавлять голос к счетчику мониторинга
|
||||
comment_page: "/api/comment" # Страница для награды за отзыв
|
||||
vote_page: "/api/vote" # Страница для награды за голос
|
||||
|
||||
hotmc_token: "SECRET_TOKEN" # Секретный токен HotMC
|
||||
mineserv_token: "SECRET_TOKEN" # Секретный токен MineServ
|
||||
minecraftrating_token: "SECRET_TOKEN" # Секретный токен MinecraftRating
|
||||
misterlauncher_token: "SECRET_TOKEN" # Секретный токен MisterLauncher
|
||||
# Что указать в FroggyMonitor?
|
||||
# В URL для поощрения за отзыв: http://{ip_сервера}:{site_port}{comment_page} -> http://example.com:8080/api/comment
|
||||
# В URL для поощрения за голос: http://{ip_сервера}:{site_port}{vote_page} -> http://example.com:8080/api/vote
|
||||
# Также возможно понадобится открыть порт на хосте
|
||||
|
||||
reward_message: # Сообщение о получении награды голосуя (%d необязательно)
|
||||
hotmc: "Вы получили %s за голос на HotMC!\nДо супер-награды осталось %d голосов."
|
||||
mineserv: "Вы получили %s за голос на MineServ!\nДо супер-награды осталось %d голосов."
|
||||
minecraftrating: "Вы получили %s за голос на MinecraftRating!\nДо супер-награды осталось %d голосов."
|
||||
misterlauncher: "Вы получили %s за голос на MisterLauncher!\nДо супер-награды осталось %d голосов."
|
||||
vote: # Награда за голос
|
||||
vault: 10 # Выдать валюту (необяз.)
|
||||
item: "diamond 10" # Выдать предмет (необяз.) (забрать предмет нельзя)
|
||||
message: "Спасибо за голос!" # Отправить сообщение (необяз.)
|
||||
commands: # Исполнить команды (необяз.)
|
||||
- "/title {player_name} subtitle на FroggyMonitor"
|
||||
- "/title {player_name} title Спасибо за отзыв!"
|
||||
|
||||
super_reward_message: # Сообщение о получении супер-награды
|
||||
general: "§6Вы получили %s за голоса на мониторингах!"
|
||||
hotmc: "§6Вы получили %s за голоса на HotMC!"
|
||||
mineserv: "§6Вы получили %s за голоса на MineServ!"
|
||||
minecraftrating: "§6Вы получили %s за голоса на MinecraftRating!"
|
||||
misterlauncher: "§6Вы получили %s за голоса на MisterLauncher!"
|
||||
add_comment: # Награда за удаление отзыва
|
||||
vault: 10
|
||||
message: "Спасибо за отзыв!"
|
||||
|
||||
player_offline_only_money: false # Если игрок оффлайн, выдавать в награду только монеты
|
||||
|
||||
super_reward_votes: 10 # Число голосов для супер-награды
|
||||
super_reward: # Супер-награды
|
||||
- type: item # Тип награды (предмет)
|
||||
name: "Алмаз x1" # Название награды (в чате)
|
||||
item:
|
||||
type: item
|
||||
material: diamond # Тип предмета
|
||||
count: 1 # Кол-во предметов
|
||||
display_name: "Алмаз (легендарный)" # Название предмета (необязательно)
|
||||
lore: | # Описание (лор) предмета (необязательно)
|
||||
Описание предмета
|
||||
Вторая строчка описания
|
||||
Третья строчка описания
|
||||
- type: money # Тип награды (валюта)
|
||||
count: 10 # Кол-во валюты
|
||||
|
||||
special_super_reward_votes: 10 # Число голосов для супер-награды (по мониторингу)
|
||||
special_super_reward: # Супер-награды по мониторингам
|
||||
- type: item
|
||||
name: "Изумруд x1"
|
||||
item:
|
||||
material: emerald
|
||||
count: 5
|
||||
display_name: "Алмаз (легендарный)"
|
||||
lore: |
|
||||
Описание предмета
|
||||
Вторая строчка описания
|
||||
Третья строчка описания
|
||||
- type: money
|
||||
count: 100
|
||||
|
||||
default_reward: # Обычные награды
|
||||
- type: item
|
||||
name: "Палка x5"
|
||||
item:
|
||||
material: stick
|
||||
count: 5
|
||||
display_name: "Палка (обычная)"
|
||||
lore: |
|
||||
Описание предмета
|
||||
Вторая строчка описания
|
||||
Третья строчка описания
|
||||
- type: money
|
||||
count: 1
|
||||
|
||||
|
||||
# Формат конфига для предмета:
|
||||
|
||||
# -- Обычный предмет --
|
||||
# type: item
|
||||
# material: <тип_предмета>
|
||||
# count: <колво_предмета>
|
||||
# enchants:
|
||||
# <название_зачарования>: <сила_зачарования>
|
||||
# nbt:
|
||||
# <нбт_ключ>: <значение>
|
||||
# display_name: <название_предмета>
|
||||
# lore:
|
||||
# - <первая_строка_описания>
|
||||
# - <вторая_строка_описания>
|
||||
# - <n_ая_строка_описания>
|
||||
|
||||
# -- Зелье --
|
||||
# type: potion
|
||||
# material: <тип_предмета>
|
||||
# effect: <тип_эффекта>
|
||||
# duration: <длительность_эффекта>
|
||||
# amplifier: <сила_эффекта>
|
||||
|
||||
# -- Кастомный предмет --
|
||||
# type: custom
|
||||
# name: <имя_кстамного_предмета>
|
||||
# count: <кол_во_предмета>
|
||||
del_comment: # Награда за удаление отзыва
|
||||
vault: -10 # Снять валюту
|
@ -1,14 +1,8 @@
|
||||
name: MonitoringReward
|
||||
version: '${project.version}'
|
||||
main: themixray.monitoringreward.Main
|
||||
api-version: 1.20
|
||||
authors: [ TheMixRay ]
|
||||
description: Monitoring Rewards
|
||||
|
||||
commands:
|
||||
reload:
|
||||
description: Перезагрузка плагина
|
||||
permission: monitoring-reward.command.reload
|
||||
permissions:
|
||||
monitoring-reward.command.reload:
|
||||
default: op
|
||||
main: ru.froggymonitor.rewardplugin.Main
|
||||
api-version: 1.13
|
||||
authors: [ FroggyMonitor ]
|
||||
description: FroggyMonitor plugin that rewards votes and comments
|
||||
website: https://froggymonitor.ru
|
||||
softdepend: [ PlaceholderAPI, Vault ]
|
Loading…
Reference in New Issue
Block a user