Skip to content

Commit

Permalink
Add statistics and scoreboard criteria for Quake3 arenas
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemaniak committed Oct 9, 2024
1 parent aa5f45d commit 8339d7a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.bytemaniak.mcquake3.network.events;

import com.bytemaniak.mcquake3.data.QuakeArenasParameters;
import com.bytemaniak.mcquake3.registry.Blocks;
import com.bytemaniak.mcquake3.registry.Packets;
import com.bytemaniak.mcquake3.registry.Sounds;
import com.bytemaniak.mcquake3.registry.Weapons;
import com.bytemaniak.mcquake3.registry.*;
import com.bytemaniak.mcquake3.util.MiscUtils;
import com.bytemaniak.mcquake3.interfaces.QuakePlayer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
Expand All @@ -13,6 +10,7 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.scoreboard.ScoreboardPlayerScore;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
Expand Down Expand Up @@ -68,6 +66,8 @@ public void recordDeath(ServerPlayerEntity player, DamageSource damageSource) {
PacketByteBuf buf = PacketByteBufs.create();
buf.writeInt(frags);
ServerPlayNetworking.send(attackerPlayer, Packets.FRAGS, buf);
attackerPlayer.incrementStat(Statistics.Q3_MATCH_FRAGS_IDENT);
attackerPlayer.getScoreboard().forEachScore(Statistics.Q3_MATCH_FRAGS_CRITERIA, attackerPlayer.getEntityName(), ScoreboardPlayerScore::incrementScore);

buf = PacketByteBufs.create();
buf.writeInt(highestFrags);
Expand Down Expand Up @@ -219,9 +219,13 @@ public void onStartTick(ServerWorld world) {
case IN_PROGRESS_STATE -> {
if (highestFrags >= FRAG_LIMIT || ticksLeft == 0) {
for (ServerPlayerEntity player : getQuakePlayers(world)) {
if (player.getName().getString().equals(winner))
if (player.getName().getString().equals(winner)) {
sendSound(player, Sounds.MATCH_WIN);
else sendSound(player, Sounds.MATCH_LOSS);
player.incrementStat(Statistics.Q3_MATCHES_WON_IDENT);
} else {
sendSound(player, Sounds.MATCH_LOSS);
player.incrementStat(Statistics.Q3_MATCHES_LOST_IDENT);
}
}

// Allow 10 seconds before transition to next map
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/bytemaniak/mcquake3/registry/Statistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public class Statistics {
public static final Identifier GAUNTLET_MEDALS = new Identifier("mcquake3:"+GAUNTLET);
public static final ScoreboardCriterion GAUNTLET_CRITERIA = ScoreboardCriterion.create("mcquake3."+GAUNTLET);

private static final String Q3_MATCH_FRAGS = "q3_match_frags";
public static final Identifier Q3_MATCH_FRAGS_IDENT = new Identifier("mcquake3:"+Q3_MATCH_FRAGS);
public static final ScoreboardCriterion Q3_MATCH_FRAGS_CRITERIA = ScoreboardCriterion.create("mcquake3."+Q3_MATCH_FRAGS);
private static final String Q3_MATCHES_WON = "q3_matches_won";
public static final Identifier Q3_MATCHES_WON_IDENT = new Identifier("mcquake3:"+Q3_MATCHES_WON);
private static final String Q3_MATCHES_LOST = "q3_matches_lost";
public static final Identifier Q3_MATCHES_LOST_IDENT = new Identifier("mcquake3:"+Q3_MATCHES_LOST);

private static void registerStat(String s, Identifier id) {
Registry.register(Registries.CUSTOM_STAT, s, id);
Stats.CUSTOM.getOrCreateStat(id);
Expand All @@ -26,5 +34,8 @@ public static void registerStats() {
registerStat(EXCELLENT, EXCELLENT_MEDALS);
registerStat(IMPRESSIVE, IMPRESSIVE_MEDALS);
registerStat(GAUNTLET, GAUNTLET_MEDALS);
registerStat(Q3_MATCH_FRAGS, Q3_MATCH_FRAGS_IDENT);
registerStat(Q3_MATCHES_WON, Q3_MATCHES_WON_IDENT);
registerStat(Q3_MATCHES_LOST, Q3_MATCHES_LOST_IDENT);
}
}
5 changes: 4 additions & 1 deletion src/main/resources/assets/mcquake3/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
"key.mcquake3.playermenu": "MCQuake3 Player Settings",
"key.mcquake3.playertaunt": "Taunt",
"stat.mcquake3.excellent_medals": "Excellent Medals",
"stat.mcquake3.gauntlet_medals": "Gauntlet Kills",
"stat.mcquake3.impressive_medals": "Impressive Medals",
"stat.mcquake3.gauntlet_medals": "Gauntlet Kills"
"stat.mcquake3.q3_match_frags": "Quake Arena frags",
"stat.mcquake3.q3_matches_lost": "Quake Arenas lost",
"stat.mcquake3.q3_matches_won": "Quake Arenas won"
}

0 comments on commit 8339d7a

Please sign in to comment.