Skip to content

Commit 75b1960

Browse files
committed
feat: added live data for basic stats
1 parent 073f8d1 commit 75b1960

8 files changed

Lines changed: 93 additions & 43 deletions

File tree

frontend/src/app/app.module.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
3-
import { HttpClientModule } from '@angular/common/http';
3+
import {HTTP_INTERCEPTORS, HttpClientModule} from '@angular/common/http';
44

55
import { AppRoutingModule } from './app-routing.module';
66
import { AppComponent } from './app.component';
@@ -12,6 +12,7 @@ import { HomeComponent } from './home/home.component';
1212
import {CookieModule} from "ngx-cookie";
1313
import {JWT_OPTIONS, JwtHelperService} from "@auth0/angular-jwt";
1414
import {NgOptimizedImage} from "@angular/common";
15+
import {AddHeaderInterceptor} from "./interceptor/backend-interceptor";
1516

1617
@NgModule({
1718
declarations: [
@@ -33,7 +34,12 @@ import {NgOptimizedImage} from "@angular/common";
3334
exports: [
3435
],
3536
providers:[{ provide: JWT_OPTIONS, useValue: JWT_OPTIONS },
36-
JwtHelperService],
37+
JwtHelperService,
38+
{
39+
provide: HTTP_INTERCEPTORS,
40+
useClass: AddHeaderInterceptor,
41+
multi: true,
42+
}],
3743
bootstrap: [AppComponent]
3844
})
3945
export class AppModule { }

frontend/src/app/home/home.component.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,53 @@
1515
<div>
1616
<div class="flex justify-between items-center">
1717
<img ngSrc="assets/img/icons8-minecraft-schwert-48.png" width="45" height="40">
18-
<p style="font-size: 35px;" class="ml-4">90</p>
18+
<p style="font-size: 35px;" class="ml-4">--</p>
1919
</div>
2020
<div class="flex justify-between items-center mt-4">
2121
<img ngSrc="assets/img/money.png" class="mr-5" width="45" height="40">
22-
<p style="font-size: 35px;" class="ml-4">2000$</p>
22+
<p style="font-size: 35px;" class="ml-4">{{latestPlayerStats.money}}$</p>
2323
</div>
2424
<div class="flex justify-between items-center mt-4">
2525
<img ngSrc="assets/img/minecraft-food.png" width="45" height="40">
26-
<p style="font-size: 35px;" class="ml-4">7</p>
26+
<p style="font-size: 35px;" class="ml-4">{{latestPlayerStats.foodLevel}}</p>
2727
</div>
2828
<div class="flex justify-between items-center mt-4">
2929
<img ngSrc="assets/img/experience-orb.webp" width="45" height="40">
30-
<p style="font-size: 35px;" class="ml-4">1300</p>
30+
<p style="font-size: 35px;" class="ml-4">{{latestPlayerStats.exp}}</p>
3131
</div>
3232
</div>
3333
<div class="inline-block h-[320px] min-h-[1em] w-0.5 self-stretch bg-black opacity-100"></div>
3434
<div>
3535
<div class="flex justify-between items-center">
3636
<img ngSrc="assets/img/Slimeball_JE2_BE2.webp" width="45" height="40">
37-
<p style="font-size: 35px;" class="ml-4">25</p>
37+
<p style="font-size: 35px;" class="ml-4">{{latestPlayerStats.sfLevel}}</p>
3838
</div>
3939
<div class="flex justify-between items-center mt-4">
4040
<img ngSrc="assets/img/minecraft-diamond.webp" width="45" height="40">
41-
<p style="font-size: 35px;" class="ml-4">4</p>
41+
<p style="font-size: 35px;" class="ml-4">{{latestPlayerStats.threatTier}}</p>
4242
</div>
4343
<div class="flex justify-between items-center mt-4">
4444
<img ngSrc="assets/img/crossed-swords.png" width="45" height="40">
45-
<p style="font-size: 35px;" class="ml-4">10</p>
45+
<p style="font-size: 35px;" class="ml-4">{{latestPlayerStats.guildRank}}</p>
4646
</div>
4747
<div class="flex justify-between items-center mt-4">
4848
<img ngSrc="assets/img/medal.png" width="50" height="50">
49-
<p style="font-size: 35px;" class="ml-4">19</p>
49+
<p style="font-size: 35px;" class="ml-4">{{latestPlayerStats.prestige}}</p>
5050
</div>
5151
</div>
5252
<div class="inline-block h-[320px] min-h-[1em] w-0.5 self-stretch bg-black opacity-100"></div>
5353
<div>
5454
<div class="flex justify-between items-center">
5555
<img ngSrc="assets/img/mcmmo.jpeg" width="45" height="40">
56-
<p style="font-size: 35px;" class="ml-4">147</p>
56+
<p style="font-size: 35px;" class="ml-4">--</p>
5757
</div>
5858
<div class="flex justify-between items-center mt-4">
5959
<img ngSrc="assets/img/potion.webp" width="45" height="40">
60-
<p style="font-size: 35px;" class="ml-4">15</p>
60+
<p style="font-size: 35px;" class="ml-4">--</p>
6161
</div>
6262
<div class="flex justify-between items-center mt-4">
6363
<img ngSrc="assets/img/skills.png" width="50" height="60">
64-
<p style="font-size: 35px;" class="ml-4">73</p>
64+
<p style="font-size: 35px;" class="ml-4">--</p>
6565
</div>
6666
<div class="flex justify-between items-center mt-4">
6767
<p style="font-size: 35px;" class="ml-4 text-white" >.</p>
@@ -72,8 +72,8 @@
7272
<h1 style="font-size: 30px">S1mple133</h1>
7373
<div id="skinContainer"></div>
7474
<div class="flex justify-between items-center mt-4">
75-
<img *ngFor="let i of [1,2,3,4,5,6,7]" ngSrc="assets/img/minecraft-heart.webp" width="35" height="35">
76-
<img *ngFor="let i of [1,2,3]" ngSrc="assets/img/minecraft-heart-black.png" width="35" height="35" >
75+
<img *ngFor="let i of heartRows" ngSrc="assets/img/minecraft-heart.webp" width="35" height="35">
76+
<!--<img *ngFor="let i of [1,2,3]" ngSrc="assets/img/minecraft-heart-black.png" width="35" height="35" >-->
7777
</div>
7878
</div>
7979
</div>

frontend/src/app/home/home.component.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {AuthService} from "../auth.service";
33
import {StatsService} from "../stats.service";
44
import {Router} from "@angular/router";
55
import {DOCUMENT} from "@angular/common";
6+
import {PlayerStats} from "../models/player-stats";
67

78
declare const genSkin: any;
89

@@ -17,13 +18,39 @@ export class HomeComponent implements OnInit {
1718
constructor(private _authService: AuthService,
1819
private _statsService: StatsService) { }
1920

21+
latestPlayerStats: PlayerStats = {
22+
exp: 0,
23+
foodLevel: 0,
24+
loc_x: 0,
25+
loc_y: 0,
26+
loc_z: 0,
27+
money: 0,
28+
health: 0,
29+
gamemode: "",
30+
lastDamageCause: "",
31+
remainingAir: 0,
32+
timeStamp: "",
33+
guildRank: 0,
34+
threatTier: 0,
35+
sfLevel: 0,
36+
prestige: 0
37+
}
38+
heartRows: number[] = []
39+
2040

2141
ngOnInit(): void {
2242
this._statsService.getSkinName().subscribe((skin: any) => {
2343
console.log(skin.skin);
2444

2545
genSkin(skin.skin, 300, 500);
2646
});
47+
48+
this._statsService.getLatestPlayerStats().subscribe(stats => {
49+
this.latestPlayerStats = stats;
50+
while(this.heartRows.length < stats.health) {
51+
this.heartRows.push(0)
52+
}
53+
})
2754
}
2855

2956
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {
2+
HttpEvent,
3+
HttpInterceptor,
4+
HttpHandler,
5+
HttpRequest, HttpHeaders,
6+
} from '@angular/common/http';
7+
import { Observable } from 'rxjs';
8+
import { Injectable } from '@angular/core';
9+
import {AuthService} from "../auth.service";
10+
import {environment} from "../../environments/environment";
11+
12+
@Injectable()
13+
export class AddHeaderInterceptor implements HttpInterceptor {
14+
constructor(private _authService: AuthService) {
15+
}
16+
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
17+
if(this._authService.getToken()) {
18+
return next.handle(req
19+
.clone({ headers: req.headers.append('Authorization', this._authService.getToken()!) }))
20+
}
21+
return next.handle(req);
22+
}
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export interface PlayerStats {
2+
exp: number,
3+
foodLevel: number,
4+
loc_x: number,
5+
loc_y: number,
6+
loc_z: number,
7+
money: number,
8+
health: number,
9+
gamemode: string,
10+
lastDamageCause: string,
11+
remainingAir: number,
12+
timeStamp: string,
13+
guildRank: number,
14+
threatTier: number,
15+
sfLevel: number,
16+
prestige: number
17+
}

frontend/src/app/stats.service.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Observable} from "rxjs";
33
import {HttpClient, HttpHeaders, HttpResponse} from "@angular/common/http";
44
import {AuthService} from "./auth.service";
55
import { environment } from 'src/environments/environment';
6+
import {PlayerStats} from "./models/player-stats";
67

78
export interface Location {
89
x: number;
@@ -26,42 +27,18 @@ export interface Account {
2627
password: string;
2728
}
2829

29-
export interface PlayerStats {
30-
username: string;
31-
location: Location;
32-
exp: number;
33-
food_level: number;
34-
money: number;
35-
health: number;
36-
gamemode: number;
37-
last_damage_cause: string;
38-
remaining_air: number;
39-
timestamp: string;
40-
}
41-
4230
@Injectable({
4331
providedIn: 'root'
4432
})
4533
export class StatsService {
4634
constructor(private http: HttpClient, private _authService: AuthService) { }
4735

48-
public getPlayerStats(playerName: string): Observable<MatrixPlayer> {
36+
public getLatestPlayerStats(): Observable<PlayerStats> {
4937
//return this.http.get<PlayerStats>(`http://localhost:8080/api/stats/${playerName}`);
50-
return this.http.get<MatrixPlayer>(environment.url + `/api/stats/${playerName}`);
38+
return this.http.get<PlayerStats>(environment.url + `/api/stats/latest`);
5139
}
5240

5341
public getSkinName(): any {
54-
if(this._authService.getToken()) {
55-
const httpOptions = {
56-
headers: new HttpHeaders({
57-
'Authorization': this._authService.getToken()!,
58-
})
59-
};
60-
61-
return this.http.get<any>(environment.url + `/api/skin/`, httpOptions);
62-
}
63-
else {
6442
return this.http.get<any>(environment.url + `/api/skin/`);
65-
}
6643
}
6744
}

frontend/src/environments/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
export const environment = {
77
production: false,
8-
url: 'https://api.matrixnetwork.org',
8+
url: 'http://localhost:8081',
99
};
1010

1111
/*

src/main/java/org/matrixnetwork/stats2/rest/StatsResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import javax.ws.rs.core.Response;
1818
import java.util.stream.Collectors;
1919

20-
@Path("/org/matrixnetwork/stats2")
20+
@Path("stats")
2121
public class StatsResource {
2222
private JSONParser parser = new JSONParser();
2323

0 commit comments

Comments
 (0)