Skip to content
Permalink
Browse files
add disconnect messages to chat-screen
  • Loading branch information
kukelekuuk committed Aug 7, 2020
1 parent 3c4b241 commit 46dd1f3216c4defbe4fc34c87eb2fbdf3facfab2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
@@ -43,7 +43,7 @@
font-size: 12px;
width: 600px;
background: rgba(25, 25, 25, 0.8);
height: 600px;
/*height: 600px;*/
overflow: hidden;
position: fixed;
left: 50%;
@@ -55,3 +55,11 @@
-moz-columns: 3;
list-style: none;
}
.kickMessage {
position: fixed;
top: 50px;
left: 50%;
width: 400px;
margin-left: -200px;
font-size: 25px;
}
@@ -7,7 +7,8 @@
</div>
<div *ngIf="tabPressed" class="playerlist">
<ul >
<li *ngFor="let player of this.players; let i = index; trackBy: trackByMessage">{{player}}</li>
<li *ngFor="let player of this.players; let i = index; trackBy: trackByMessage" [innerHTML]="player"></li>
</ul>
</div>

<div *ngIf="kickedMessage" class="kickMessage alert alert-secondary" role="alert" [innerHTML]="'Disconnected: ' + kickedMessage"></div>
@@ -36,6 +36,7 @@ export class ChatScreenComponent implements OnInit, AfterViewChecked, OnDestroy
};
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
private disconnecting = false;
kickedMessage = "";

ngAfterViewChecked(): void {
this.scrollToBottom();
@@ -82,13 +83,13 @@ export class ChatScreenComponent implements OnInit, AfterViewChecked, OnDestroy
ngOnInit(): void {
this.scrollToBottom();
if (this.botContainer.botData === undefined) {
this.router.navigate(["/"])
this.router.navigate(["/"]);
return;
}
this.mineflayer = remote.require("mineflayer");
this.ChatMessage = this.mineflayer.ChatMessage;

this.motdparser = remote.require("mcmotdparser")
this.motdparser = require("mcmotdparser");
this.ChatMessage = remote.require('prismarine-chat')('1.16');

const botData = this.botContainer.botData;
@@ -101,25 +102,30 @@ export class ChatScreenComponent implements OnInit, AfterViewChecked, OnDestroy
session.clientToken = this.botContainer.clientToken;
session.selectedProfile = this.botContainer.selectedProfile;
botData.session = session;
console.log(botData);
this.bot = this.mineflayer.createBot(botData);
this.bot.on("message", (jsonMsg) => {
const message = new this.ChatMessage(jsonMsg);
this.addMessage(message)
})
});
this.bot.once("login", () => {
this.changeDetector.detectChanges();
this.loadPlayer();
setInterval(() => this.loadPlayer(), 5000);
});
this.bot.once("kicked", (reason: string, loggedIn: boolean) => {
console.log(`kicked: ${reason}`);
this.motdparser.toHtml(new this.ChatMessage(JSON.parse(reason)).toMotd(), (err, res: string) => {
this.kickedMessage = res;
this.changeDetector.detectChanges();
});
});
}

ngOnDestroy(): void {
this.disconnect();
}

private addMessage(message: ChatMessage) {
console.log()
const date = new Date();
const timestamp = `[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}] `;

0 comments on commit 46dd1f3

Please sign in to comment.