Skip to content

Commit

Permalink
Merge pull request #15 from Alexdoru/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
Alexdoru authored Jul 2, 2022
2 parents 55da01b + b72f3e9 commit 59d86d6
Show file tree
Hide file tree
Showing 33 changed files with 714 additions and 345 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
}
apply plugin: 'net.minecraftforge.gradle.forge'

version = "2.0"
version = "2.1"
group = "fr.alexdoru"
archivesBaseName = "[1.8.9]MegaWallsEnhancements"

Expand All @@ -31,7 +31,6 @@ dependencies {
}

jar {
appendix = minecraft.version
manifest.attributes(
"FMLCorePlugin": 'fr.alexdoru.megawallsenhancementsmod.asm.ASMLoadingPlugin',
'FMLCorePluginContainsFMLMod': 'Yes, yes it does'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ public void processCommand(ICommandSender sender, String[] args) {
.append(": ");
for (Iterator<Map.Entry<String, Integer>> iterator = sortByDecreasingValue1(getPlayers(TEAM)).entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, Integer> entry = iterator.next();
String name = entry.getKey();
String squadname = SquadEvent.getSquad().get(name);
if (squadname != null) {
strBuilder.append(squadname).append(" (").append(entry.getValue()).append(")");
} else {
strBuilder.append(name).append(" (").append(entry.getValue()).append(")");
}
strBuilder.append(SquadEvent.getSquadname(entry.getKey())).append(" (").append(entry.getValue()).append(")");
if (iterator.hasNext()) {
strBuilder.append(", ");
}
Expand Down
80 changes: 45 additions & 35 deletions src/main/java/fr/alexdoru/fkcountermod/events/KillCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fr.alexdoru.megawallsenhancementsmod.enums.MWClass;
import fr.alexdoru.megawallsenhancementsmod.events.SquadEvent;
import fr.alexdoru.megawallsenhancementsmod.utils.ChatUtil;
import fr.alexdoru.megawallsenhancementsmod.utils.StringUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.network.NetworkPlayerInfo;
Expand Down Expand Up @@ -94,7 +95,20 @@ public class KillCounter {
"(\\w{1,16}) was chewed up by (\\w{1,16}).*",
"(\\w{1,16}) was chemically cheesed by (\\w{1,16}).*",
"(\\w{1,16}) was turned into cheese whiz by (\\w{1,16}).*",
"(\\w{1,16}) was magically squeaked by (\\w{1,16}).*"
"(\\w{1,16}) was magically squeaked by (\\w{1,16}).*",
/*Natural deaths messages*/
"(\\w{1,16}) starved to death\\.",
"(\\w{1,16}) hit the ground too hard\\.",
"(\\w{1,16}) blew up\\.",
"(\\w{1,16}) exploded\\.",
"(\\w{1,16}) tried to swim in lava\\.",
"(\\w{1,16}) went up in flames\\.",
"(\\w{1,16}) burned to death\\.",
"(\\w{1,16}) suffocated in a wall\\.",
"(\\w{1,16}) suffocated\\.",
"(\\w{1,16}) fell out of the world\\.",
"(\\w{1,16}) had a block fall on them\\.",
"(\\w{1,16}) drowned\\."
};
private static final String[] SCOREBOARD_PREFIXES = {"[R]", "[G]", "[Y]", "[B]"};
private static final String[] DEFAULT_PREFIXES = {"c", "a", "e", "9"}; // RED GREEN YELLOW BLUE
Expand Down Expand Up @@ -143,48 +157,45 @@ public static boolean processMessage(String FormattedText, String UnformattedTex
return false;
}

/*
* Kill message detection
*/
for (Pattern kill_pattern : KILL_PATTERNS) {
for (Pattern pattern : KILL_PATTERNS) {

Matcher killMessageMatcher = kill_pattern.matcher(UnformattedText);
Matcher matcher = pattern.matcher(UnformattedText);

if (killMessageMatcher.matches()) {
if (matcher.matches()) {

String killedPlayer = killMessageMatcher.group(1);
String killer = killMessageMatcher.group(2);
String[] split = FormattedText.split("\u00a7");

if (split.length >= 7) {
String killedTeam = split[2].substring(0, 1);
String killerTeam = split[6].substring(0, 1);
if (removeKilledPlayer(killedPlayer, killedTeam)) {
addKill(killer, killerTeam);
playersPresentInGame.add(killedPlayer);
playersPresentInGame.add(killer);
if (matcher.groupCount() == 2) {
String killedPlayer = matcher.group(1);
String killer = matcher.group(2);
String killedTeamColor = StringUtil.getLastColorCodeBefore(FormattedText, killedPlayer).replace("\u00a7", "");
String killerTeamColor = StringUtil.getLastColorCodeBefore(FormattedText, killer).replace("\u00a7", "");
if (!killedTeamColor.equals("") && !killerTeamColor.equals("")) {
if (removeKilledPlayer(killedPlayer, killedTeamColor)) {
addKill(killer, killerTeamColor);
playersPresentInGame.add(killedPlayer);
playersPresentInGame.add(killer);
}
FKCounterGui.instance.updateDisplayText();
}
FKCounterGui.instance.updateDisplayText();
}

if (ConfigHandler.strengthParticules) {
spawnParticles(killer);
}

String squadmate = SquadEvent.getSquad().get(killer);
if (squadmate != null) {
ChatUtil.addChatMessage(new ChatComponentText(FormattedText.replace(killer, squadmate)));
if (ConfigHandler.strengthParticules) {
spawnParticles(killer);
}
ChatUtil.addChatMessage(new ChatComponentText(FormattedText.replace(killer, SquadEvent.getSquadname(killer)).replace(killedPlayer, SquadEvent.getSquadname(killedPlayer))));
return true;
}
squadmate = SquadEvent.getSquad().get(killedPlayer);
if (squadmate != null) {
ChatUtil.addChatMessage(new ChatComponentText(FormattedText.replace(killedPlayer, squadmate)));

if (matcher.groupCount() == 1) {
String killedPlayer = matcher.group(1);
String killedTeamColor = StringUtil.getLastColorCodeBefore(FormattedText, killedPlayer).replace("\u00a7", "");
if (!killedTeamColor.equals("")) {
if (removeKilledPlayer(killedPlayer, killedTeamColor)) {
playersPresentInGame.add(killedPlayer);
}
FKCounterGui.instance.updateDisplayText();
}
ChatUtil.addChatMessage(new ChatComponentText(FormattedText.replace(killedPlayer, SquadEvent.getSquadname(killedPlayer))));
return true;
}

ChatUtil.addChatMessage(new ChatComponentText(FormattedText));
return true;

}

}
Expand All @@ -208,7 +219,6 @@ public static int getKills(int team) {
if (isNotValidTeam(team)) {
return 0;
}

int kills = 0;
for (int k : teamKillsArray[team].values()) {
kills += k;
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/fr/alexdoru/fkcountermod/gui/FKCounterGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public class FKCounterGui extends MyCachedGui {
+ EnumChatFormatting.YELLOW + "3" + EnumChatFormatting.DARK_GRAY + " / "
+ EnumChatFormatting.BLUE + "4";
/*used as an example when in the settings*/
private static final String DUMMY_TEXT_PLAYERS = EnumChatFormatting.RED + "Red" + EnumChatFormatting.WHITE + ": 12 " + EnumChatFormatting.GRAY + "- RedPlayer (5)\n"
+ EnumChatFormatting.GREEN + "Green" + EnumChatFormatting.WHITE + ": 9 " + EnumChatFormatting.GRAY + "- GreenPlayer (4)\n"
+ EnumChatFormatting.YELLOW + "Yellow" + EnumChatFormatting.WHITE + ": 5 " + EnumChatFormatting.GRAY + "- YellowPlayer (3)\n"
+ EnumChatFormatting.BLUE + "Blue" + EnumChatFormatting.WHITE + ": 4 " + EnumChatFormatting.GRAY + "- BluePlayer (2)";
private static final String DUMMY_TEXT_PLAYERS = EnumChatFormatting.RED + "R" + EnumChatFormatting.WHITE + " 12 :" + EnumChatFormatting.WHITE + " RedPlayer (5)\n"
+ EnumChatFormatting.GREEN + "G" + EnumChatFormatting.WHITE + " 9 :" + EnumChatFormatting.WHITE + " GreenPlayer (4)\n"
+ EnumChatFormatting.YELLOW + "Y" + EnumChatFormatting.WHITE + " 5 :" + EnumChatFormatting.WHITE + " YellowPlayer (3)\n"
+ EnumChatFormatting.BLUE + "B" + EnumChatFormatting.WHITE + " 4 :" + EnumChatFormatting.WHITE + " BluePlayer (2)";
public static FKCounterGui instance;
private final int BACKGROUND_COLOR = new Color(0, 0, 0, 64).getRGB();
private final int BACKGROUND_COLOR = new Color(0, 0, 0, 96).getRGB();
private final int DUMMY_BACKGROUND_COLOR = new Color(255, 255, 255, 127).getRGB();

public FKCounterGui() {
Expand Down Expand Up @@ -60,7 +60,7 @@ public void render() {
int x = absolutePos[0];
int y = absolutePos[1];
if (ConfigHandler.draw_background) {
drawRect(x - 1, y - 1, x + getWidth(), y + getHeight(), BACKGROUND_COLOR);
drawRect(x - 2, y - 2, x + getWidth() + 1, y + getHeight(), BACKGROUND_COLOR);
}
GlStateManager.pushMatrix();
{
Expand Down Expand Up @@ -150,23 +150,23 @@ public void updateDisplayText() {
if (i != 0) {
strBuilder.append("\n");
}
strBuilder.append(getColorPrefixFromTeam(team))
.append(getTeamNameFromTeam(team)).append(EnumChatFormatting.WHITE)
.append(": ").append(getKills(team));
strBuilder.append(getColorPrefixFromTeam(team)).append(getTeamNameFromTeam(team).charAt(0)).append(EnumChatFormatting.WHITE).append(" ").append(getKills(team));
HashMap<String, Integer> teamkillsmap = KillCounter.sortByDecreasingValue1(KillCounter.getPlayers(team));
if (!teamkillsmap.isEmpty()) {
int playerAmount = 0;
boolean isFirst = true;
for (Entry<String, Integer> playerEntry : teamkillsmap.entrySet()) {
String squadname = SquadEvent.getSquad().get(playerEntry.getKey());
if (squadname != null) {
strBuilder.append(EnumChatFormatting.GRAY).append(" - ").append(squadname).append(" (").append(playerEntry.getValue()).append(")");
if (isFirst) {
strBuilder.append(" : ");
} else {
strBuilder.append(EnumChatFormatting.GRAY).append(" - ").append(playerEntry.getKey()).append(" (").append(playerEntry.getValue()).append(")");
strBuilder.append(" - ");
}
strBuilder.append(SquadEvent.getSquadname(playerEntry.getKey())).append(" (").append(playerEntry.getValue()).append(")");
playerAmount++;
if (playerAmount == ConfigHandler.playerAmount) {
break;
}
isFirst = false;
}
}
i++;
Expand Down
46 changes: 26 additions & 20 deletions src/main/java/fr/alexdoru/fkcountermod/utils/ScoreboardParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.alexdoru.fkcountermod.utils;

import fr.alexdoru.megawallsenhancementsmod.gui.LastWitherHPGui;
import fr.alexdoru.megawallsenhancementsmod.utils.StringUtil;
import net.minecraft.scoreboard.Scoreboard;

import java.util.ArrayList;
Expand All @@ -13,7 +14,7 @@ public class ScoreboardParser {
private static final Pattern GAME_ID_PATTERN = Pattern.compile("\\s*\\d+/\\d+/\\d+\\s+([\\d\\w]+)\\s*", Pattern.CASE_INSENSITIVE);
private static final Pattern MW_TITLE_PATTERN = Pattern.compile("\\s*MEGA\\sWALLS\\s*", Pattern.CASE_INSENSITIVE);
private static final Pattern MW_INGAME_PATTERN = Pattern.compile("[0-9]+\\sFinals?\\s[0-9]+\\sF\\.\\sAssists?");
private static final Pattern PREGAME_LOBBY_PATTERN = Pattern.compile("\\s*Players:\\s*[0-9]+/[0-9]+\\s*");
private static final Pattern PREGAME_LOBBY_PATTERN = Pattern.compile("Players:\\s*[0-9]+/[0-9]+");
private static final Pattern WITHER_ALIVE_PATTERN = Pattern.compile("\\s*\\[.\\] Wither HP: ?(\\d+).*", Pattern.CASE_INSENSITIVE);
private static final Pattern WITHER_ALIVE_HEART_PATTERN = Pattern.compile("\\s*\\[.\\] Wither [\u2764\u2665]: ?(\\d+).*", Pattern.CASE_INSENSITIVE);

Expand All @@ -36,65 +37,70 @@ public ScoreboardParser(Scoreboard scoreboard) {
return;
}
isMWEnvironement = true;
List<String> scoresColor = ScoreboardUtils.getFormattedSidebarText(scoreboard);
List<String> scoresRaw = ScoreboardUtils.stripControlCodes(scoresColor);
List<String> formattedSidebarLines = ScoreboardUtils.getFormattedSidebarText(scoreboard);
List<String> unformattedSidebarLines = ScoreboardUtils.stripControlCodes(formattedSidebarLines);

if (scoresRaw.size() == 0) {
if (unformattedSidebarLines.size() == 0) {
return;
}

Matcher matcher = GAME_ID_PATTERN.matcher(scoresRaw.get(0));
Matcher matcher = GAME_ID_PATTERN.matcher(unformattedSidebarLines.get(0));
if (!matcher.matches()) {
for (String line : unformattedSidebarLines) {
if (PREGAME_LOBBY_PATTERN.matcher(line).find()) {
gameId = null;
preGameLobby = true;
isInMwGame = false;
return;
}
}
return;
}

gameId = matcher.group(1);

for (String line : scoresRaw) {
for (String line : unformattedSidebarLines) {
if (MW_INGAME_PATTERN.matcher(line).find()) {
isInMwGame = true;
continue;
}
if (PREGAME_LOBBY_PATTERN.matcher(line).matches()) {
if (PREGAME_LOBBY_PATTERN.matcher(line).find()) {
gameId = null;
preGameLobby = true;
isInMwGame = false;
return;
}
}

if (scoresRaw.size() < 7) {
if (unformattedSidebarLines.size() < 7) {
return;
}

if (scoresRaw.get(1).contains("Walls Fall:") || scoresRaw.get(1).contains("Gates Open:")) {
if (unformattedSidebarLines.get(1).contains("Walls Fall:") || unformattedSidebarLines.get(1).contains("Gates Open:")) {
isitPrepPhase = true;
}

int eliminated_teams = 0;
int witherHP = 1000;

for (int i = 3; i < Math.min(scoresRaw.size(), 7); i++) {
for (int i = 3; i < Math.min(unformattedSidebarLines.size(), 7); i++) {

String line = scoresRaw.get(i);
String line = unformattedSidebarLines.get(i);
/*Wither alive detection*/
final Matcher matcher1 = WITHER_ALIVE_PATTERN.matcher(line);
String colorCode;
if (matcher1.matches()) {

String lineColor = scoresColor.get(i);
String colorCode = lineColor.split("\u00a7")[1].substring(0, 1);
String formattedLine = formattedSidebarLines.get(i);
colorCode = StringUtil.getLastColorCodeBefore(formattedLine, "\\[").replace("\u00a7", "");
aliveWithers.add(colorCode);
witherHP = Integer.parseInt(matcher1.group(1));

} else {
final Matcher matcher2 = WITHER_ALIVE_HEART_PATTERN.matcher(line);
if (matcher2.matches()) {

String lineColor = scoresColor.get(i);
String colorCode = lineColor.split("\u00a7")[1].substring(0, 1);
String formattedLine = formattedSidebarLines.get(i);
colorCode = StringUtil.getLastColorCodeBefore(formattedLine, "\\[").replace("\u00a7", "");
aliveWithers.add(colorCode);
witherHP = 2 * Integer.parseInt(matcher2.group(1));

}
}

Expand All @@ -104,7 +110,7 @@ public ScoreboardParser(Scoreboard scoreboard) {

}

if (eliminated_teams == 3 || scoresRaw.get(1).contains("None!:")) {
if (eliminated_teams == 3 || unformattedSidebarLines.get(1).contains("None!:")) {
hasgameended = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,22 @@ public static List<String> getFormattedSidebarText() {
* Item at index 0 is the first line etc
*/
public static List<String> getFormattedSidebarText(Scoreboard scoreboard) {

List<String> lines = new ArrayList<>();
ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(1);

if (objective == null) {
return lines;
}

Collection<Score> scores = scoreboard.getSortedScores(objective);

List<Score> list = scores.stream()
.filter(input -> input != null && input.getPlayerName() != null && !input.getPlayerName().startsWith("#"))
.collect(Collectors.toList());

List<Score> list = scores.stream().filter(input -> input != null && input.getPlayerName() != null && !input.getPlayerName().startsWith("#")).collect(Collectors.toList());
if (list.size() > 15) {
scores = Lists.newArrayList(Iterables.skip(list, scores.size() - 15));
} else {
scores = list;
}

for (Score score : scores) {
ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName());
lines.add(ScorePlayerTeam.formatPlayerName(team, ""));
}

Collections.reverse(lines);
return lines;
}
Expand Down Expand Up @@ -106,11 +97,9 @@ public static List<String> stripControlCodes(List<String> ListIn) {
*/
public static String getSidebarTitle(Scoreboard scoreboard) {
ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(1);

if (objective == null) {
return "";
}

return objective.getDisplayName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MegaWallsEnhancementsMod {

public static final String modid = "mwenhancements";
public static final String modName = "MegaWallsEnhancements";
public static final String version = "2.0";
public static final String version = "2.1";
public static final KeyBinding toggleDroppedItemLimit = new KeyBinding("Toggle dropped item limit", 0, "MegaWallsEnhancements");
public static final KeyBinding newNickKey = new KeyBinding("New Random Nick", 0, "MegaWallsEnhancements");
public static File configurationFile;
Expand Down Expand Up @@ -60,6 +60,7 @@ public void init(FMLInitializationEvent event) {
ClientCommandHandler.instance.registerCommand(new CommandStalk());
ClientCommandHandler.instance.registerCommand(new CommandPlancke());
ClientCommandHandler.instance.registerCommand(new CommandScanGame());
ClientCommandHandler.instance.registerCommand(new CommandAddAlias());
ClientCommandHandler.instance.registerCommand(new CommandHypixelShout());
ClientCommandHandler.instance.registerCommand(new CommandHypixelReply());
ClientCommandHandler.instance.registerCommand(new CommandMWEnhancements());
Expand Down
Loading

0 comments on commit 59d86d6

Please sign in to comment.