-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ce731f
commit 854c45d
Showing
10 changed files
with
162 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package de.hysky.skyblocker.skyblock.dungeon; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import de.hysky.skyblocker.skyblock.entity.MobGlow; | ||
|
||
public enum DungeonClass { | ||
UNKNOWN("Unknown", MobGlow.NO_GLOW), | ||
HEALER("Healer", 0x820dd1), | ||
MAGE("Mage", 0x36c6e3), | ||
BERSERK("Berserk", 0xfa5b16), | ||
ARCHER("Archer", 0xed240e), | ||
TANK("Tank", 0x138717); | ||
|
||
private static final Map<String, DungeonClass> CLASSES = Arrays.stream(values()) | ||
.collect(Collectors.toUnmodifiableMap(DungeonClass::displayName, Function.identity())); | ||
|
||
private final String name; | ||
private final int color; | ||
|
||
DungeonClass(String name, int colour) { | ||
this.name = name; | ||
this.color = colour; | ||
} | ||
|
||
public String displayName() { | ||
return this.name; | ||
} | ||
|
||
/** | ||
* @return The color of the class in RGB format. | ||
*/ | ||
public int color() { | ||
return this.color; | ||
} | ||
|
||
public static DungeonClass from(String name) { | ||
return CLASSES.getOrDefault(name, UNKNOWN); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonPlayerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package de.hysky.skyblocker.skyblock.dungeon.secrets; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.jetbrains.annotations.Range; | ||
|
||
import de.hysky.skyblocker.annotations.Init; | ||
import de.hysky.skyblocker.events.DungeonEvents; | ||
import de.hysky.skyblocker.skyblock.dungeon.DungeonClass; | ||
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr; | ||
import it.unimi.dsi.fastutil.objects.Object2ReferenceMap; | ||
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
|
||
public class DungeonPlayerManager { | ||
/** | ||
* @implNote Same as {@link de.hysky.skyblocker.skyblock.tabhud.widget.DungeonPlayerWidget#PLAYER_PATTERN} | ||
*/ | ||
private static final Pattern PLAYER_TAB_PATTERN = Pattern.compile("\\[\\d*\\] (?:\\[[A-Za-z]+\\] )?(?<name>[A-Za-z0-9_]*) (?:.* )?\\((?<class>\\S*) ?(?<level>[LXVI]*)\\)"); | ||
private static final Object2ReferenceMap<String, DungeonClass> PLAYER_CLASSES = new Object2ReferenceOpenHashMap<>(5); | ||
|
||
@Init | ||
public static void init() { | ||
DungeonEvents.DUNGEON_STARTED.register(DungeonPlayerManager::onDungeonStart); | ||
} | ||
|
||
public static DungeonClass getClassFromPlayer(PlayerEntity player) { | ||
String name = player.getGameProfile().getName(); | ||
|
||
return PLAYER_CLASSES.getOrDefault(name, DungeonClass.UNKNOWN); | ||
} | ||
|
||
private static void onDungeonStart() { | ||
reset(); | ||
|
||
for (int i = 0; i < 5; i++) { | ||
Matcher matcher = getPlayerFromTab(i + 1); | ||
|
||
if (matcher != null) { | ||
String name = matcher.group("name"); | ||
DungeonClass dungeonClass = DungeonClass.from(matcher.group("class")); | ||
|
||
if (dungeonClass != DungeonClass.UNKNOWN) PLAYER_CLASSES.put(name, dungeonClass); | ||
} | ||
} | ||
} | ||
|
||
private static void reset() { | ||
PLAYER_CLASSES.clear(); | ||
} | ||
|
||
private static Matcher getPlayerFromTab(@Range(from = 1, to = 5) int index) { | ||
return PlayerListMgr.regexAt(1 + (index - 1) * 4, PLAYER_TAB_PATTERN); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters