Skip to content

Commit

Permalink
Implemented method for whispering to player
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGreatViolet committed Jul 5, 2022
1 parent 6b1a563 commit f93b7a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,23 @@ public void registerCallbacks() {
// Chat
Chat chat = new Chat();

JavaCallback whisperCallback = (V8Object, V8Array) -> {
String playerName = V8Array.getString(0);
String message = V8Array.getString(1);

Player player = Bukkit.getPlayer(playerName);

if (player != null) {
player.sendMessage(message);
}

return null;
};

runner.getRuntime().registerJavaMethod(chat, "broadcast", "javaBroadcast",
new Class[] { String.class });
runner.getRuntime().registerJavaMethod(whisperCallback, "javaWhisper");


// Players
Players players = new Players();
Expand Down
7 changes: 7 additions & 0 deletions src/npm-package/src/chat/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import {Player} from "../entities/player";

function broadcast(message: string) {
// @ts-ignore
javaBroadcast(message);
}

function whisper(player: Player, message: string) {
// @ts-ignore
javaWhisper(player.name, message);
}

export default {
broadcast,
}

0 comments on commit f93b7a6

Please sign in to comment.