2015-08-06 07:45:39 +02:00
|
|
|
package mineplex.votifier;
|
|
|
|
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
import com.vexsoftware.votifier.model.Vote;
|
|
|
|
import com.vexsoftware.votifier.model.VotifierEvent;
|
|
|
|
import mineplex.core.MiniPlugin;
|
|
|
|
import mineplex.core.account.CoreClientManager;
|
|
|
|
import mineplex.core.donation.DonationManager;
|
2015-08-08 13:35:25 +02:00
|
|
|
import mineplex.core.votifier.VotifierCommand;
|
|
|
|
import mineplex.serverdata.Region;
|
|
|
|
import mineplex.serverdata.commands.ServerCommandManager;
|
|
|
|
import mineplex.serverdata.data.PlayerStatus;
|
|
|
|
import mineplex.serverdata.redis.RedisDataRepository;
|
|
|
|
import mineplex.serverdata.servers.ServerManager;
|
2015-08-06 07:45:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by shaun on 15-08-05.
|
|
|
|
*/
|
|
|
|
public class VotifierManager extends MiniPlugin
|
|
|
|
{
|
2015-08-08 13:35:25 +02:00
|
|
|
private RedisDataRepository<PlayerStatus> _usPlayerRepo;
|
|
|
|
private RedisDataRepository<PlayerStatus> _euPlayerRepo;
|
|
|
|
|
2015-08-06 07:45:39 +02:00
|
|
|
public VotifierManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
|
|
|
{
|
|
|
|
super("Votifier", plugin);
|
|
|
|
|
2015-08-08 13:35:25 +02:00
|
|
|
_usPlayerRepo = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
|
|
|
Region.US, PlayerStatus.class, "playerStatus");
|
|
|
|
_euPlayerRepo = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
|
|
|
Region.EU, PlayerStatus.class, "playerStatus");
|
2015-08-06 07:45:39 +02:00
|
|
|
|
2015-08-08 13:35:25 +02:00
|
|
|
ServerCommandManager.getInstance().registerCommandType("VotifierCommand", VotifierCommand.class);
|
|
|
|
}
|
2015-08-06 07:45:39 +02:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void handleVote(VotifierEvent event)
|
|
|
|
{
|
|
|
|
Vote vote = event.getVote();
|
|
|
|
|
|
|
|
System.out.println("New Vote: " + vote.getUsername());
|
2015-08-08 13:35:25 +02:00
|
|
|
|
|
|
|
PlayerStatus usStatus = _usPlayerRepo.getElement(vote.getUsername());
|
|
|
|
// VotifierCommand command = new VotifierCommand(vote.getUsername(), "PhiTest-1");
|
|
|
|
// command.publish();
|
|
|
|
|
|
|
|
if (usStatus != null)
|
|
|
|
{
|
|
|
|
System.out.println("Found on US Server: " + usStatus.getServer());
|
|
|
|
VotifierCommand command = new VotifierCommand(vote.getUsername(), usStatus.getServer());
|
|
|
|
command.publish();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println("Not found on US Server!");
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerStatus euStatus = _euPlayerRepo.getElement(vote.getUsername());
|
|
|
|
if (euStatus != null)
|
|
|
|
{
|
|
|
|
System.out.println("Found on EU Server: " + euStatus.getServer());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println("Not found on EU Server!");
|
|
|
|
}
|
2015-08-06 07:45:39 +02:00
|
|
|
}
|
|
|
|
}
|