Skip to content

Commit

Permalink
Merge pull request #3 from MSWS/1.3.1-dev
Browse files Browse the repository at this point in the history
1.3.1 dev
  • Loading branch information
MSWS authored Mar 31, 2022
2 parents a81a61d + 145ca07 commit 577c986
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 61 deletions.
10 changes: 7 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>xyz.msws</groupId>
Expand Down Expand Up @@ -32,5 +30,11 @@
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
27 changes: 7 additions & 20 deletions src/main/java/xyz/msws/admintools/data/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import xyz.msws.admintools.data.DataStructs.ActionType;
import xyz.msws.admintools.data.DataStructs.Role;
import xyz.msws.admintools.data.jb.JailRole;
Expand All @@ -13,8 +15,13 @@
* Compares by time
*/
public abstract class Action implements Comparable<Action> {
@Getter
protected ActionType type;
@Getter
@Setter
protected String player, target;
@Getter
@Setter
protected Role playerRole, targetRole;
protected String[] other;
protected String line;
Expand All @@ -29,26 +36,6 @@ public Action(String line) {
this.line = line;
}

public String getPlayer() {
return player;
}

public String getTarget() {
return target;
}

public Role getPlayerRole() {
return playerRole;
}

public Role getTargetRole() {
return targetRole;
}

public ActionType getType() {
return type;
}

public String[] getOther() {
return other;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xyz/msws/admintools/data/DataStructs.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static interface ActionType {
}

public static enum GenericActionType implements ActionType {
DAMAGE("damaged %s (%s) for %s"), KILL("killed %s (%s)"), NADE("threw a(n) %s"), GHOST_RESPAWN("respawned as ghost");
DAMAGE("damaged %s (%s) for %s"), KILL("killed %s (%s)"), NADE("threw a %s"), GHOST_RESPAWN("respawned as ghost");

String sum;

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/xyz/msws/admintools/data/jb/JailAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ private ActionType findActionType() {
return GenericActionType.KILL;
} else if (line.contains("dropped the weapon")) {
return JailActionType.DROP_WEAPON;
} else if (line.contains(" picked up ")) {
return JailActionType.PICKUP;
} else if (line.endsWith("has been fired by an admin")) {
return JailActionType.FIRE;
} else if (line.endsWith("has passed warden")) {
Expand Down Expand Up @@ -173,9 +175,10 @@ private String[] findOther() {
}
if (!(type instanceof JailActionType jbType))
return new String[] { "Invalid Type" };
String name, weapon;
switch (jbType) {
case BUTTON:
String name = line.substring(
name = line.substring(
line.substring(0, line.length() - 1).lastIndexOf(
line.contains("pressed button 'Unknown'") ? "(" : "'", line.length() - 2) + 1,
line.length() - 1);
Expand All @@ -184,13 +187,18 @@ private String[] findOther() {
case DROP_WEAPON:
return new String[] { line.substring(line.lastIndexOf(" ") + 1, line.length() - 1) };
case RESKIN:
String weapon = line.substring(line.indexOf("reskinned weapon_") + "reskinned weapon_".length(),
weapon = line.substring(line.indexOf("reskinned weapon_") + "reskinned weapon_".length(),
line.indexOf(" ", line.lastIndexOf("weapon_")));
if (line.endsWith("(not previously owned)")) {
return new String[] { weapon, "their own" };
}
return new String[] { weapon, line
.substring(line.indexOf("previous owner: ") + "previous owner: ".length(), line.length() - 1) };
case PICKUP:
name = line.substring(line.indexOf("picked up ") + "picked up ".length(),
line.lastIndexOf("'s "));
weapon = line.substring(line.lastIndexOf(" ") + 1, line.length() - 1);
return new String[] { name, weapon };
default:
return new String[] {};
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/xyz/msws/admintools/data/jb/JailActionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
*/
public enum JailActionType implements ActionType {
BUTTON("pressed %s (%s)"), WARDEN("took warden"),
VENTS("broke vents"),
DROP_WEAPON("dropped a(n) %s"), WARDEN_DEATH("died as warden"), PASS("passed warden"),
FIRE("was fired"),
RESKIN("reskinned %2$s's %1$s");
VENTS("broke vents"), DROP_WEAPON("dropped a(n) %s"), WARDEN_DEATH("died as warden"), PASS("passed warden"),
FIRE("was fired"), RESKIN("reskinned %2$s's %1$s"), PICKUP("picked up %s's %s");

private final String sum;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/xyz/msws/admintools/data/jb/JailRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Enum to identify a player's role on Jailbreak
*/
public enum JailRole implements Role {
WARDEN("W"), GUARD("G"), PRISONER("P"), REBEL("R"), SPECTATOR("S"), WORLD("World"), GHOST("Ghost"),
WARDEN("W"), GUARD("G"), PRISONER("P"), REBEL("R"), SPECTATOR("S"), WORLD("World"), GHOST("Ghost"), ST("ST"),
UNKNOWN("Unknown");

private final String icon;
Expand All @@ -24,7 +24,7 @@ public boolean isCT() {
}

public boolean isT() {
return this == PRISONER || this == REBEL;
return this == PRISONER || this == REBEL || this == ST;
}

public boolean isAlive() {
Expand Down
80 changes: 52 additions & 28 deletions src/main/java/xyz/msws/admintools/parsers/JBParser.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package xyz.msws.admintools.parsers;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import xyz.msws.admintools.Monitor;
import xyz.msws.admintools.data.*;
import xyz.msws.admintools.data.Button;
import xyz.msws.admintools.data.ButtonDatabase;
import xyz.msws.admintools.data.DataStructs.GenericActionType;
import xyz.msws.admintools.data.DataStructs.Role;
import xyz.msws.admintools.data.jb.JailAction;
import xyz.msws.admintools.data.jb.JailActionType;
import xyz.msws.admintools.data.jb.JailRole;
import xyz.msws.admintools.utils.MSG;

import java.io.File;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Parses Jailbreak Logs
*/
Expand Down Expand Up @@ -66,6 +74,7 @@ public void parse(String line) {
checkNades();
if (config.showGunPlants())
checkGuns();
checkST();
checkSpectator();
jbActions.clear();
lines.clear();
Expand Down Expand Up @@ -269,33 +278,32 @@ private void checkNades() {
* Checks if a CT drops a gun and a T uses the same type of gun soon after
*/
private void checkGuns() {
List<JailAction> guns = jbActions.stream()
.filter(act -> act.getType() == JailActionType.DROP_WEAPON && act.getPlayerRole().isCT())
List<JailAction> pickups = jbActions.stream()
.filter(act -> act.getType() == JailActionType.PICKUP && act.getPlayerRole().isT())
.collect(Collectors.toList());
Iterator<JailAction> it = guns.iterator();
while (it.hasNext()) {
JailAction drop = it.next();
for (JailAction pickup : pickups) {
JailAction known = jbActions.stream().filter(a -> a.getPlayer().equals(pickup.getOther()[0])).findFirst()
.orElse(null);
if (known == null)
continue;
Role dropRole = known.getPlayerRole();
if (!dropRole.isCT())
continue;
JailAction firstDrop = jbActions.stream()
.filter(a -> a.getType() == JailActionType.DROP_WEAPON && a.getPlayer().equals(known.getPlayer())
&& a.getOther()[0].equals(pickup.getOther()[1]))
.findFirst().orElse(null);
if (firstDrop == null) {
continue;
}
JailAction death = jbActions.stream()
.filter(a -> a.getType() == GenericActionType.KILL && a.getTarget().equals(drop.getPlayer()))
.filter(a -> a.getType() == GenericActionType.KILL && a.getTarget().equals(known.getPlayer()))
.findFirst().orElse(null);
if (death == null)
if (death.getTime() == firstDrop.getTime()) {
continue;
if (death.getTime() == drop.getTime() || death.getTime() + 1 == drop.getTime())
it.remove();
}

for (JailAction act : jbActions.stream()
.filter(act -> act.getType() == GenericActionType.DAMAGE && act.getPlayerRole().isT())
.collect(Collectors.toList())) {
List<JailAction> ds = guns.stream()
.filter(p -> p.getTime() <= act.getTime() && p.getTime() > act.getTime() - config.getGunTimeout()
&& p.getOther()[0].equals(act.getOther()[1]))
.collect(Collectors.toList());
for (JailAction p : ds) {
print("\nGun Plants");
print(p.simplify() + " and " + act.getPlayer() + " (" + act.getPlayerRole().getIcon()
+ ") used one shortly after");
}
print("\nGunplants");
print(pickup.simplify() + ", dropped at " + firstDrop.getTimeString());
}
}

Expand All @@ -312,6 +320,22 @@ private void checkSpectator() {
}
}

/**
* Checks is a CT killed an ST
*/
private void checkST() {
List<JailAction> kills = jbActions.stream()
.filter(act -> act.getType() == GenericActionType.KILL && act.getTargetRole() == JailRole.ST
&& act.getPlayerRole().isCT())
.collect(Collectors.toList());
if (kills.isEmpty())
return;
for (JailAction kill : kills) {
print("\nST Kills");
print(kill.simplify());
}
}

/**
* Returns true if CTs should not be shooting prisoners during this time
*
Expand Down
1 change: 0 additions & 1 deletion src/main/java/xyz/msws/admintools/parsers/TTTParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,4 @@ private void print(String line) {
System.out.println(line);
lines.add(line);
}

}

0 comments on commit 577c986

Please sign in to comment.