Merge origin/master
This commit is contained in:
@@ -73,6 +73,9 @@ public class AnuraCore extends JavaPlugin {
|
||||
if (this.getConfig().getBoolean("is-main-lobby")) {
|
||||
Setup.setupXPBattle();
|
||||
}
|
||||
if (this.getConfig().getBoolean("enable-votifier")) {
|
||||
Setup.setupVotifier();
|
||||
}
|
||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", signs);
|
||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new Teleports());
|
||||
sql.queryUpdate("DELETE FROM coreServers WHERE name = '" + this.getConfig().getString("server-name") + "'");
|
||||
|
||||
@@ -45,6 +45,7 @@ public class Setup {
|
||||
c.addDefault("spawn.Z", 0);
|
||||
c.addDefault("spawn.yaw", 0d);
|
||||
c.addDefault("spawn.pitch", 0d);
|
||||
c.addDefault("enable-votifier", false);
|
||||
c.options().copyDefaults(true);
|
||||
c.options().header("Config File of the Anura Core-Plugin:");
|
||||
}
|
||||
@@ -310,4 +311,9 @@ public class Setup {
|
||||
s.registerNewObjective("xpBattleIngame", "dummy");
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupVotifier() {
|
||||
AnuraCore.getInstance().getServer().getPluginManager().registerEvents(new VotifierListener(), AnuraCore.getInstance());
|
||||
AnuraCore.getInstance().getServer().getMessenger().registerIncomingPluginChannel(AnuraCore.getInstance(), "BungeeCord", new VotifierListener());
|
||||
}
|
||||
}
|
||||
|
||||
127
src/de/anura/core/events/VotifierListener.java
Normal file
127
src/de/anura/core/events/VotifierListener.java
Normal file
@@ -0,0 +1,127 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.vexsoftware.votifier.model.Vote;
|
||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Money;
|
||||
import de.anura.core.AnuraCore;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.Socket;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
public class VotifierListener implements Listener, PluginMessageListener {
|
||||
|
||||
@EventHandler
|
||||
public void onVotifierEvent(VotifierEvent event) {
|
||||
Vote vote = event.getVote();
|
||||
String timestamp = vote.getTimeStamp();
|
||||
int timestampInt;
|
||||
try {
|
||||
timestampInt = Integer.parseInt(timestamp);
|
||||
} catch (NumberFormatException ex) {
|
||||
timestampInt = (int) (System.currentTimeMillis() / 1000);
|
||||
}
|
||||
try {
|
||||
ResultSet rs1 = Core.getMySql().querySelect("SELECT id FROM `players` WHERE name = '" + vote.getUsername() + "'");
|
||||
if (!rs1.next()) {
|
||||
return;
|
||||
}
|
||||
int money = 25;
|
||||
int playerId;
|
||||
playerId = rs1.getInt("id");
|
||||
ResultSet rs2 = Core.getMySql().querySelect("SELECT * FROM `voteUsers` WHERE playerId = '" + playerId + "'");
|
||||
if (rs2.first()) {
|
||||
int lastVoteDate = rs2.getInt("dateOfLastVote");
|
||||
int votesInRow;
|
||||
votesInRow = rs2.getInt("votesInARow");
|
||||
if (lastVoteDate > ((System.currentTimeMillis() / 1000) - (60 * 60 * 24))) {
|
||||
votesInRow++;
|
||||
if (votesInRow == 10) {
|
||||
money += 50;
|
||||
votesInRow = 0;
|
||||
}
|
||||
} else {
|
||||
votesInRow = 1;
|
||||
}
|
||||
Core.getMySql().queryUpdate("UPDATE `voteUsers` SET `dateOfLastVote`=" + timestampInt + ",`votesInARow`=" + votesInRow + " WHERE playerId=" + playerId);
|
||||
} else {
|
||||
Core.getMySql().queryUpdate("INSERT INTO `voteUsers`(`playerId`, `dateOfLastVote`, `votesInARow`) VALUES (SELECT id FROM `players` WHERE name = '" + vote.getUsername() + "'," + timestampInt + ",1)");
|
||||
}
|
||||
addPlayerMoney(money, vote);
|
||||
} catch (SQLException ex) {
|
||||
Errors.reportException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayerMoney(int money, Vote vote) {
|
||||
try {
|
||||
if (AnuraCore.getInstance().getServer().getOnlinePlayers().isEmpty()) {
|
||||
Socket so = new Socket("127.0.0.1", 27767);
|
||||
OutputStream os = so.getOutputStream();
|
||||
BufferedWriter ps = new BufferedWriter(new OutputStreamWriter(os));
|
||||
ps.write("X3Nw;a+F!R_p~(Wj#LZc");
|
||||
ps.newLine();
|
||||
ps.write("vote");
|
||||
ps.newLine();
|
||||
ps.write(vote.getUsername());
|
||||
ps.newLine();
|
||||
ps.write(money + "");
|
||||
ps.newLine();
|
||||
ps.flush();
|
||||
ps.close();
|
||||
so.close();
|
||||
} else {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(stream);
|
||||
out.writeUTF("money");
|
||||
out.writeUTF(vote.getUsername());
|
||||
out.writeInt(money);
|
||||
Player p = Iterables.get(AnuraCore.getInstance().getServer().getOnlinePlayers(), 0);
|
||||
p.sendPluginMessage(AnuraCore.getInstance(), "BungeeCord", stream.toByteArray());
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Errors.reportException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
|
||||
if (!channel.equals("BungeeCord")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||
DataInputStream in = new DataInputStream(stream);
|
||||
|
||||
if (in.readUTF().equalsIgnoreCase("money")) {
|
||||
String playername = in.readUTF();
|
||||
Player p = Bukkit.getPlayer(playername);
|
||||
int money = Integer.parseInt(in.readUTF());
|
||||
Core.statusMsg(p, "Vote_Normal", true);
|
||||
if (money == 75) {
|
||||
Core.statusMsg(p, "Vote_10_Times", true);
|
||||
}
|
||||
Money.payMoney(p, money);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Errors.reportException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ name: Core
|
||||
main: de.anura.core.AnuraCore
|
||||
version: 0.9
|
||||
author: kaenganxt
|
||||
softdepend: [Multiverse-Core]
|
||||
softdepend: [Multiverse-Core, Votifier]
|
||||
commands:
|
||||
setjumper:
|
||||
description: Admin Command
|
||||
|
||||
Reference in New Issue
Block a user