*Added Vote (not ready)
This commit is contained in:
@@ -72,6 +72,7 @@ public class AnuraCore extends JavaPlugin {
|
|||||||
Setup.setupCommands();
|
Setup.setupCommands();
|
||||||
if (this.getConfig().getBoolean("is-main-lobby")) {
|
if (this.getConfig().getBoolean("is-main-lobby")) {
|
||||||
Setup.setupXPBattle();
|
Setup.setupXPBattle();
|
||||||
|
Setup.setupVotifier();
|
||||||
}
|
}
|
||||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", signs);
|
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", signs);
|
||||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new Teleports());
|
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new Teleports());
|
||||||
|
|||||||
@@ -311,4 +311,9 @@ public class Setup {
|
|||||||
s.registerNewObjective("xpBattleIngame", "dummy");
|
s.registerNewObjective("xpBattleIngame", "dummy");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setupVotifier() {
|
||||||
|
AnuraCore.getInstance().getServer().getPluginManager().registerEvents(new de.anura.core.events.VotifierListener(), AnuraCore.getInstance());
|
||||||
|
AnuraCore.getInstance().getServer().getMessenger().registerIncomingPluginChannel(AnuraCore.getInstance(), "BungeeCord", new VotifierListener());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
111
src/de/anura/core/events/VotifierListener.java
Normal file
111
src/de/anura/core/events/VotifierListener.java
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
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.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
private int timestampInt;
|
||||||
|
private int votesInRow;
|
||||||
|
private int playerId;
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onVotifierEvent(VotifierEvent event) {
|
||||||
|
Vote vote = event.getVote();
|
||||||
|
String timestamp = vote.getTimeStamp();
|
||||||
|
|
||||||
|
try {
|
||||||
|
timestampInt = Integer.parseInt(timestamp);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
timestampInt = (int) (System.currentTimeMillis() / 1000);
|
||||||
|
}
|
||||||
|
addPlayerMoney(25, vote);
|
||||||
|
try {
|
||||||
|
ResultSet rs1 = Core.getMySql().querySelect("SELECT * FROM `players` WHERE name = '" + vote.getUsername() + "'");
|
||||||
|
if (!rs1.next()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
playerId = rs1.getInt("id");
|
||||||
|
ResultSet rs2 = Core.getMySql().querySelect("SELECT * FROM `voteUsers` WHERE playerId = '" + playerId + "'");
|
||||||
|
if (rs2.first()) {
|
||||||
|
int lastVoteDate = rs2.getInt("dateOfLastVote");
|
||||||
|
votesInRow = rs2.getInt("votesInARow");
|
||||||
|
if (lastVoteDate > (System.currentTimeMillis() - 86400)) {
|
||||||
|
votesInRow++;
|
||||||
|
if (votesInRow == 10) {
|
||||||
|
addPlayerMoney(50, vote);
|
||||||
|
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 (" + playerId + "," + timestampInt + ",1)");
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
Errors.reportException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayerMoney(int money, Vote vote) {
|
||||||
|
/*if (Bukkit.getPlayer(vote.getUsername()) != null) {
|
||||||
|
Money.payMoney(Bukkit.getPlayer(vote.getUsername()), money);
|
||||||
|
} else {*/
|
||||||
|
try {
|
||||||
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream out = new DataOutputStream(stream);
|
||||||
|
out.writeUTF("money");
|
||||||
|
out.writeUTF(vote.getUsername());
|
||||||
|
out.writeInt(money);
|
||||||
|
|
||||||
|
Iterables.get(AnuraCore.getInstance().getServer().getOnlinePlayers(), 0).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());
|
||||||
|
Money.payMoney(p, money);
|
||||||
|
if (money == 25) {
|
||||||
|
Core.getl("Vote_Normal", p);
|
||||||
|
} else if (money == 50) {
|
||||||
|
Core.getl("Vote_10_Times", p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Errors.reportException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ name: Core
|
|||||||
main: de.anura.core.AnuraCore
|
main: de.anura.core.AnuraCore
|
||||||
version: 0.9
|
version: 0.9
|
||||||
author: kaenganxt
|
author: kaenganxt
|
||||||
softdepend: [Multiverse-Core]
|
softdepend: [Multiverse-Core, Votifier]
|
||||||
commands:
|
commands:
|
||||||
setjumper:
|
setjumper:
|
||||||
description: Admin Command
|
description: Admin Command
|
||||||
|
|||||||
Reference in New Issue
Block a user