Search in sources :

Example 1 with Vote

use of com.vexsoftware.votifier.model.Vote in project VotingPlugin by Ben12345rocks.

the class VotiferEvent method onVotiferEvent.

/**
 * On votifer event.
 *
 * @param event
 *            the event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onVotiferEvent(VotifierEvent event) {
    Vote vote = event.getVote();
    final String voteSite = vote.getServiceName();
    final String voteUsername = vote.getUsername().trim();
    Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {

        @Override
        public void run() {
            ServerData.getInstance().addServiceSite(voteSite);
        }
    });
    if (voteUsername.length() == 0) {
        plugin.getLogger().warning("No name from vote on " + voteSite);
        return;
    }
    plugin.getLogger().info("Recieved a vote from '" + voteSite + "' by player '" + voteUsername + "'!");
    plugin.debug("PlayerUsername: " + voteUsername);
    plugin.debug("VoteSite: " + voteSite);
    Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {

        @Override
        public void run() {
            String voteSiteName = plugin.getVoteSiteName(voteSite);
            ArrayList<String> sites = configVoteSites.getVoteSitesNames();
            if (sites != null) {
                if (!sites.contains(voteSiteName) && Config.getInstance().getAutoCreateVoteSites()) {
                    plugin.getLogger().warning("VoteSite " + voteSiteName + " doe not exist, generaterating one...");
                    ConfigVoteSites.getInstance().generateVoteSite(voteSiteName);
                }
            } else if (Config.getInstance().getAutoCreateVoteSites()) {
                plugin.getLogger().warning("VoteSite " + voteSiteName + " doe not exist, generaterating one...");
                ConfigVoteSites.getInstance().generateVoteSite(voteSiteName);
            }
            PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(voteSiteName), voteUsername);
            plugin.getServer().getPluginManager().callEvent(voteEvent);
            if (voteEvent.isCancelled()) {
                plugin.debug("Vote cancelled");
                return;
            }
            playerVote(voteUsername, voteSite, true);
        }
    });
}
Also used : Vote(com.vexsoftware.votifier.model.Vote) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Vote

use of com.vexsoftware.votifier.model.Vote in project Ublisk by Derkades.

the class Voting method onVote.

@EventHandler(priority = EventPriority.HIGH)
public void onVote(VotifierEvent event) {
    Vote vote = event.getVote();
    UPlayer player;
    try {
        player = new UPlayer(vote.getUsername());
    } catch (PlayerNotFoundException e) {
        // TODO Deal with player not online exception
        e.printStackTrace();
        return;
    }
    int points = Random.getRandomInteger(1, 3);
    player.setVotingPoints(player.getVotingPoints() + points);
    Ublisk.broadcastPrefixedMessage(player.getName() + " has voted and got " + points + " points! Vote at " + Var.VOTE_URL);
    Logger.log(LogLevel.INFO, "Vote", player.getName() + " has voted at " + vote.getServiceName() + " (" + vote.getAddress() + ") and got " + points + " points.");
}
Also used : Vote(com.vexsoftware.votifier.model.Vote) UPlayer(xyz.derkades.ublisk.utils.UPlayer) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Vote

use of com.vexsoftware.votifier.model.Vote in project solinia3-core by mixxit.

the class Solinia3CoreVoteListener method onVotifierEvent.

@EventHandler(priority = EventPriority.NORMAL)
public void onVotifierEvent(VotifierEvent event) {
    Vote vote = event.getVote();
    Player player = plugin.getServer().getPlayer(vote.getUsername());
    String uuid = "";
    if (player != null)
        uuid = player.getUniqueId().toString();
    else
        try {
            uuid = Utils.getUUIDFromPlayerName(vote.getUsername());
            uuid = java.util.UUID.fromString(uuid.replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5")).toString();
        } catch (IOException e1) {
            System.out.println("Cannot find player to associate inspiration to (" + vote.getUsername() + ") [WebLookup]");
        }
    if (uuid == null || uuid.equals("")) {
        System.out.println("Cannot find player to associate inspiration to (" + vote.getUsername() + ")");
        return;
    }
    System.out.println("Vote received: " + vote.getUsername() + " UUID: " + uuid + " from " + vote.getServiceName() + " " + vote.getAddress());
    try {
        ISoliniaPlayer solplayer = StateManager.getInstance().getPlayerManager().getPlayerAndDoNotCreate(UUID.fromString(uuid));
        if (solplayer != null) {
            solplayer.setInspiration(solplayer.getInspiration() + 1);
            if (player != null) {
                player.sendMessage(ChatColor.YELLOW + "* You have gained inspiration! See /inspiration");
            }
        } else {
            System.out.println("Cannot find player to associate inspiration to (" + vote.getUsername() + ")");
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Vote(com.vexsoftware.votifier.model.Vote) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) IOException(java.io.IOException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Vote

use of com.vexsoftware.votifier.model.Vote in project MyMaid2 by jaoafa.

the class Event_VoteReceived method onVotifierEvent.

@EventHandler
public void onVotifierEvent(VotifierEvent event) {
    Vote vote = event.getVote();
    String name = vote.getUsername();
    VoteReceive(name);
}
Also used : Vote(com.vexsoftware.votifier.model.Vote) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Vote (com.vexsoftware.votifier.model.Vote)4 EventHandler (org.bukkit.event.EventHandler)4 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Player (org.bukkit.entity.Player)1 UPlayer (xyz.derkades.ublisk.utils.UPlayer)1 PlayerNotFoundException (xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)1