Skip to content

Commit

Permalink
Fixed vote detection in Eggwars and Survival Games
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusAntons committed Sep 13, 2017
1 parent c1509e9 commit 8718cbc
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected String[] getVoteCategories() {
}

public enum HealthType {
NORMAL("♥"), DOUBLE("♥♥"), TRIPLE("♥♥♥");
HALF("♡"), NORMAL("♥"), DOUBLE("♥♥"), TRIPLE("♥♥♥");

public final String symbol;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
package net.frozenbit.plugin5zig.cubecraft.gamemodes;

import eu.the5zig.util.minecraft.ChatColor;
import net.frozenbit.plugin5zig.cubecraft.CubeCraftPlayer;
import net.frozenbit.plugin5zig.cubecraft.Rank;
import net.frozenbit.plugin5zig.cubecraft.stalker.Stalker;

public class SurvivalGamesMode extends TimeLootVotableMode {
import java.util.Map;

import static java.lang.String.format;

public class SurvivalGamesMode extends VotableCubeCraftGameMode {
private static Stalker stalker;

private static ChatColor lootTypeColor(String itemType) {
if (itemType == null) {
return ChatColor.GRAY;
}
switch (itemType) {
case "Basic":
return ChatColor.GREEN;
case "Normal":
return ChatColor.YELLOW;
case "Overpowered":
return ChatColor.DARK_RED;
default:
return null;
}
}

@Override
public String getName() {
return "SurvivalGames";
Expand All @@ -16,4 +39,84 @@ public Stalker getStalker() {
stalker = new Stalker(this);
return stalker;
}

@Override
protected String formatVoteString(CubeCraftPlayer player, Map<String, String> vote) {
StringBuilder voteStringBuilder = new StringBuilder()
.append(lootTypeColor(vote.get("loot")))
.append(player.getName())
.append(ChatColor.RESET)
.append(" ");
if (vote.containsKey("health")) {
HealthType healthVote = HealthType.valueOf(vote.get("health").toUpperCase());
voteStringBuilder
.append(ChatColor.RED)
.append(healthVote.symbol)
.append(ChatColor.RESET)
.append(" ");
}
if (vote.containsKey("time")) {
DaytimeType daytimeVote = DaytimeType.valueOf(vote.get("time").toUpperCase());
voteStringBuilder.append(daytimeVote);
}
return voteStringBuilder.toString();
}

@Override
public String formatVoteResult(Map<String, String> draw) {
String itemType = draw.get("loot");
HealthType health = HealthType.valueOf(draw.get("health").toUpperCase());
DaytimeType daytimeType = DaytimeType.valueOf(draw.get("time").toUpperCase());
return format("%s%s%s / %s / %s", lootTypeColor(itemType), itemType, ChatColor.RESET, health, daytimeType.getChatName());
}

@Override
protected boolean isShownInVoterList(CubeCraftPlayer player) {
return player.isStaff() || Rank.GOLD.compareTo(player.getRank()) <= 0;
}

@Override
protected String[] getVoteCategories() {
return new String[]{"health", "loot", "time"};
}

public enum HealthType {
HARDCORE("♡"), NORMAL("♥"), DOUBLE("♥♥"), TRIPLE("♥♥♥");

public final String symbol;

HealthType(String symbol) {
this.symbol = symbol;
}


@Override
public String toString() {
return ChatColor.RED + symbol + ChatColor.RESET;
}
}

public enum DaytimeType {
DAY("Day", "●"),
SUNSET("Sunset", "◓"),
NIGHT("Night", "☾"),
NONE("", "");

public final String chatName;
public final String symbol;

DaytimeType(String chatName, String symbol) {
this.chatName = chatName;
this.symbol = symbol;
}

public String getChatName() {
return chatName;
}

@Override
public String toString() {
return ChatColor.GOLD + symbol + ChatColor.RESET;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void onMatch(GameMode gameMode, String key, IPatternResult match) {
return;
}
if (key.equals("generic.join")) {
countdown = 10;
countdown = 20;
} else if (key.startsWith("message.receive")) {
RespondCommandHandler.MessageType messageType = RespondCommandHandler.MessageType.valueOf(
Iterables.getLast(Splitter.on('.').splitToList(key)).toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ public int compare(TowerDefenceGameMode.Tower o1, TowerDefenceGameMode.Tower o2)
return Integer.compare(o1.price, o2.price);
}
};
public static final String COIN_SCORE_NAME = "§6⛃§e Coins";
public static final String CASTLE_HEALTH_SCORE_NAME = "§c❤§d Castle Health";
public static final String EXP_SCORE_NAME = "§3✦§b EXP";
public static final Pattern COIN_PATTERN = Pattern.compile("(\\d+) Coins");
public static final Pattern EXP_PATTERN = Pattern.compile("(\\d+) EXP");
private static final Pattern PRICE_PATTERN = Pattern.compile("Price: (\\d+) coins");
private Map<String, TowerDefenceGameMode.Tower> towers;
private long tickCount;
Expand Down Expand Up @@ -54,16 +53,21 @@ public void onTick(TowerDefenceGameMode gameMode) {
tickCount++;
if (tickCount % 5 == 0) {
HashMap<String, Integer> lines = The5zigAPI.getAPI().getSideScoreboard().getLines();
if (lines.containsKey(COIN_SCORE_NAME)) {
gameMode.setCoins(lines.get(COIN_SCORE_NAME));
for (String line : lines.keySet()) {
if (tickCount % 10 == 0) {
Matcher coinMatcher = COIN_PATTERN.matcher(line);
if (coinMatcher.matches()) {
gameMode.setCoins(Integer.parseInt(coinMatcher.group(1)));
break;
}
} else {
Matcher expMatcher = EXP_PATTERN.matcher(line);
if (expMatcher.matches()) {
gameMode.setExp(Integer.parseInt(expMatcher.group(1)));
break;
}
}
}
if (lines.containsKey(CASTLE_HEALTH_SCORE_NAME)) {
gameMode.setCastleHealth(lines.get(CASTLE_HEALTH_SCORE_NAME));
}
if (lines.containsKey(EXP_SCORE_NAME)) {
gameMode.setExp(lines.get(EXP_SCORE_NAME));
}

if (gameMode.getState() == GameState.LOBBY && !lines.containsKey("§5Map:")) {
long startTime = gameMode.getTime();
gameMode.setState(GameState.GAME);
Expand All @@ -75,7 +79,7 @@ public void onTick(TowerDefenceGameMode gameMode) {
@Override
public void onChestSetSlot(TowerDefenceGameMode gameMode, String containerTitle, int slot, ItemStack itemStack) {
super.onChestSetSlot(gameMode, containerTitle, slot, itemStack);
if ("Tower builder".equals(containerTitle) && slot < 18 && !"iron_bars".equals(itemStack.getKey())) {
if ("Tower builder".equals(containerTitle) && slot < 27 && !"iron_bars".equals(itemStack.getKey())) {
String towerName = ChatColor.stripColor(itemStack.getDisplayName());
if (itemStack.getLore().size() < 2) {
The5zigAPI.getLogger().warn("No lore for {}", towerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import net.frozenbit.plugin5zig.cubecraft.CubeCraftPlayer;
import net.frozenbit.plugin5zig.cubecraft.Main;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

public class Stalker {

Expand All @@ -22,7 +22,7 @@ public Stalker(GameMode gameMode) {
this.gameMode = gameMode;
storage = new Storage(gameMode);
ownName = The5zigAPI.getAPI().getGameProfile().getName();
stalkedPlayerList = new CopyOnWriteArrayList<>();
stalkedPlayerList = new ArrayList<>();
}

public void onKill(String victim, String killer) {
Expand Down Expand Up @@ -64,12 +64,14 @@ public void onPlayerListUpdate(final List<CubeCraftPlayer> playerList) {
new Thread() {
@Override
public void run() {
for (CubeCraftPlayer cubeCraftPlayer : playerList) {
maxNameWidth = Math.max(maxNameWidth, The5zigAPI.getAPI().getRenderHelper().getStringWidth(cubeCraftPlayer.getName()));
StalkedPlayer stalkedPlayer = storage.getStalkedPlayer(cubeCraftPlayer);
if (stalkedPlayer.getKills() != 0 || stalkedPlayer.getDeaths() != 0)
++shownPlayerCount;
stalkedPlayerList.add(stalkedPlayer);
synchronized (stalkedPlayerList) {
for (CubeCraftPlayer cubeCraftPlayer : playerList) {
maxNameWidth = Math.max(maxNameWidth, The5zigAPI.getAPI().getRenderHelper().getStringWidth(cubeCraftPlayer.getName()));
StalkedPlayer stalkedPlayer = storage.getStalkedPlayer(cubeCraftPlayer);
if (stalkedPlayer.getKills() != 0 || stalkedPlayer.getDeaths() != 0)
++shownPlayerCount;
stalkedPlayerList.add(stalkedPlayer);
}
}
}
}.start();
Expand All @@ -80,9 +82,11 @@ public List<StalkedPlayer> getStalkedPlayerList() {
}

public StalkedPlayer getStalkedPlayerById(UUID id) {
for (StalkedPlayer stalkedPlayer : stalkedPlayerList) {
if (stalkedPlayer.getId().equals(id)) {
return stalkedPlayer;
synchronized (stalkedPlayerList) {
for (StalkedPlayer stalkedPlayer : stalkedPlayerList) {
if (stalkedPlayer.getId().equals(id)) {
return stalkedPlayer;
}
}
}
return null;
Expand Down
16 changes: 9 additions & 7 deletions src/main/resources/core/messages/cubecraft.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,25 @@ duels.start=Go!!!
eggwars.starting=Teleporting to map...
eggwars.countdown=You will released in (%d) seconds!
eggwars.start=Go!
eggwars.vote.health=(%p) voted for (Normal|Double|Triple) health! %d votes?!
eggwars.draw.health=Selected (Normal|Double|Triple) health!.+
eggwars.vote.items=(%p) voted for (Normal|Basic|Overpowered) items! %d votes?!
eggwars.vote.health=(%p) voted for (Half|Normal|Double|Triple) health! %d votes?!
eggwars.draw.health=Selected (Half|Normal|Double|Triple) health!.+
eggwars.vote.items=(%p) voted for (Normal|Hardcore|Overpowered) items! %d votes?!
eggwars.draw.items=Selected (Overpowered|Hardcore|Normal) items!.+
#
sg.countdown=Survival Games starting in %d seconds?
sg.pregame=There is a (%d) second grace period before PvP is enabled
sg.start=The grace period has ended - PvP is enabled
sg.vote.time=(%p) voted for (Day|Night|Sunset)(?:-time)?! %d votes?!
sg.draw.time=(?:Randomly selected|Selected time of day) (Day|Night|Sunset)(?:-time)? (?:from polled votes|by default)!
sg.vote.time=(%p) voted for (Day|Night|Sunset)(?: Time)?! %d votes?!
sg.draw.time=Selected (Day|Night|Sunset)(?: Time)? time-of-day (?:randomly from polled votes|by default)!
sg.vote.loot=(%p) voted for (Overpowered|Basic|Normal)(?: Items)?! %d votes?!
sg.draw.loot=(?:Randomly selected|Selected loot) (Overpowered|Basic|Normal)(?: Items)? (?:from polled votes|by default)!
sg.draw.loot=Selected (Overpowered|Basic|Normal) Items items (?:randomly from polled votes|by default)!
sg.vote.health=(%p) voted for (Hardcore|Normal|Double|Triple) Health! %d votes?!
sg.draw.health=Selected (Hardcore|Normal|Double|Triple) Health health (?:randomly from polled votes|by default)!
#
skywars.starting=Teleporting to map...
skywars.vote.loot=(%p) voted for (Overpowered|Basic|Normal) chests! %d votes?!
skywars.draw.loot=Selected (Overpowered|Basic|Normal) chests.+
skywars.vote.time=(%p) voted for (Day|Night|Sunset)(?: time)?! %d votes?!
skywars.vote.time=(%p) voted for (Day|Night|Sunset)(?: Time)?! %d votes?!
skywars.draw.time=Selected (Day(?: time)|Night(?: time)|Sunset).*
skywars.countdown.lobby=(?:Team )?SkyWars starting in (%d) seconds
skywars.countdown.starting=You will be released in (%d) seconds
Expand Down

0 comments on commit 8718cbc

Please sign in to comment.