Mineplex2018-withcommit/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java

70 lines
2.2 KiB
Java
Raw Normal View History

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;
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;
/**
* Created by shaun on 15-08-05.
*/
public class VotifierManager extends MiniPlugin
{
private RedisDataRepository<PlayerStatus> _usPlayerRepo;
private RedisDataRepository<PlayerStatus> _euPlayerRepo;
public VotifierManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super("Votifier", plugin);
_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");
ServerCommandManager.getInstance().registerCommandType("VotifierCommand", VotifierCommand.class);
}
@EventHandler
public void handleVote(VotifierEvent event)
{
Vote vote = event.getVote();
System.out.println("New Vote: " + vote.getUsername());
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!");
}
}
}