Skip to content

Commit

Permalink
implement unvote interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kory33 committed Apr 16, 2017
1 parent 6b5d1be commit 022635e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ public class MessageConfigurationNodes {
public static final String VOTE_UI_HEADING = VOTE_UI_ROOT + ".heading";
public static final String VOTE_UI_SCORE_SELECTION = VOTE_UI_ROOT + ".scoreselection";
public static final String VOTE_UI_NONE_AVAILABLE = VOTE_UI_ROOT + ".noavailablevotes";

public static final String UNVOTE_UI = UI_ROOT + ".unvote";
public static final String UNVOTE_UI_HEADING = UNVOTE_UI + ".heading";
public static final String UNVOTE_UI_COMFIRM = UNVOTE_UI + ".comfirm";
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.github.kory33.signvote.ui;

import java.util.ArrayList;
import java.util.Optional;

import org.bukkit.entity.Player;

import com.github.kory33.signvote.configurable.JSONConfiguration;
import com.github.kory33.signvote.constants.MessageConfigurationNodes;
import com.github.kory33.signvote.model.VotePoint;
import com.github.kory33.signvote.session.VoteSession;
import com.github.ucchyocean.messaging.tellraw.ClickEventType;
import com.github.ucchyocean.messaging.tellraw.MessageComponent;
import com.github.ucchyocean.messaging.tellraw.MessageParts;

public class PlayerUnvoteInterface extends PlayerChatInterface {
private final VoteSession session;
Expand All @@ -21,9 +27,42 @@ public PlayerUnvoteInterface(Player player, VoteSession session, VotePoint voteP
this.messageConfig = messageConfig;
}

private MessageParts getConfigMessagePart(String configurationNode) {
return new MessageParts(this.messageConfig.getString(configurationNode));
}

private MessageParts getHeading() {
String votePointName = this.votePoint.getName();
Optional<Integer> optionalVotedScore = this.session.getVoteManager().getVotedScore(this.targetPlayer, votePointName);
if (!optionalVotedScore.isPresent()) {
throw new IllegalStateException("Player Unvote Interface has been invoked against a non-voted votepoint!");
}

int votedScore = optionalVotedScore.get();

String message = messageConfig.getFormatted(MessageConfigurationNodes.UNVOTE_UI_HEADING, votePointName, votedScore) + "\n";
return new MessageParts(message);
}

private MessageParts getUnvoteButton() {
MessageParts button = this.getConfigMessagePart(MessageConfigurationNodes.UI_BUTTON);
String runCommand = String.join(" ", "/signvote unvote", this.session.getName(), this.votePoint.getName());
button.setClickEvent(ClickEventType.RUN_COMMAND, runCommand);
return button;
}

@Override
protected MessageComponent constructInterfaceMessages() {
// TODO construct MessageComponent sent for unvote interface
return null;
MessageParts header = this.getConfigMessagePart(MessageConfigurationNodes.UI_HEADER);
MessageParts footer = this.getConfigMessagePart(MessageConfigurationNodes.UI_FOOTER);

ArrayList<MessageParts> messageList = new ArrayList<>();
messageList.add(header);
messageList.add(this.getHeading());
messageList.add(this.getUnvoteButton());
messageList.add(this.getConfigMessagePart(MessageConfigurationNodes.UNVOTE_UI_COMFIRM));
messageList.add(footer);

return new MessageComponent(messageList);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
"heading": "§aSelect a point to vote to §6{0}",
"scoreselection": "§6{0} §aPoints(§e{1} §atimes remaining)",
"noavailablevotes": "§eYou have casted all your votes."
},
"unvote": {
"heading": "§aYou have already voted to §6{0} §awith a score of §6{1}.\n§eClick the button below to CANCEL this vote.",
"comfirm": "§cComfirm the vote to be cancelled.\n"
}
}
}

0 comments on commit 022635e

Please sign in to comment.