-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
11 changed files
with
437 additions
and
322 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
23 changes: 23 additions & 0 deletions
23
src/main/java/plu/capstone/playerpiano/addon/minecraftmod/command/ModCommands.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,23 @@ | ||
package plu.capstone.playerpiano.addon.minecraftmod.command; | ||
|
||
import com.mojang.brigadier.context.CommandContext; | ||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import net.minecraft.text.Text; | ||
|
||
public class ModCommands { | ||
|
||
public static void registerModCommands() { | ||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { | ||
TestCommand.register(dispatcher); | ||
PauseUnpauseCommand.register(dispatcher); | ||
}); | ||
} | ||
|
||
public static void sendFeedback(CommandContext<ServerCommandSource> context, String text) { | ||
sendFeedback(context, Text.of(text)); | ||
} | ||
public static void sendFeedback(CommandContext<ServerCommandSource> context, Text msg) { | ||
context.getSource().sendFeedback(() -> msg, false); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/plu/capstone/playerpiano/addon/minecraftmod/command/PauseUnpauseCommand.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,22 @@ | ||
package plu.capstone.playerpiano.addon.minecraftmod.command; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import net.minecraft.server.command.CommandManager; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import plu.capstone.playerpiano.addon.minecraftmod.piano.PianoController; | ||
|
||
public class PauseUnpauseCommand { | ||
|
||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { | ||
dispatcher.register(CommandManager.literal("piano-pause").executes(PauseUnpauseCommand::execute)); | ||
} | ||
|
||
private static int execute(CommandContext<ServerCommandSource> context) { | ||
|
||
PianoController.getInstance().pauseUnpauseSong(); | ||
|
||
return 1; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/plu/capstone/playerpiano/addon/minecraftmod/command/TestCommand.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,20 @@ | ||
package plu.capstone.playerpiano.addon.minecraftmod.command; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import net.minecraft.server.command.CommandManager; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
|
||
public class TestCommand { | ||
|
||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { | ||
dispatcher.register(CommandManager.literal("hello").executes(TestCommand::execute)); | ||
} | ||
|
||
private static int execute(CommandContext<ServerCommandSource> context) { | ||
String text = "Hello, " + context.getSource().getPlayer().getDisplayName().getString() + "!"; | ||
ModCommands.sendFeedback(context, text); | ||
return 1; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/plu/capstone/playerpiano/addon/minecraftmod/piano/PianoController.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,48 @@ | ||
package plu.capstone.playerpiano.addon.minecraftmod.piano; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpRequest.BodyPublishers; | ||
import java.net.http.HttpResponse.BodyHandlers; | ||
import java.net.http.HttpResponse; | ||
import java.time.Duration; | ||
import java.util.function.Consumer; | ||
|
||
|
||
public class PianoController { | ||
|
||
HttpClient client = HttpClient.newHttpClient(); | ||
|
||
private static PianoController instance; | ||
|
||
private String uuid; | ||
|
||
public static PianoController getInstance() { | ||
if(instance == null) instance = new PianoController(); | ||
return instance; | ||
} | ||
|
||
public void onConnect(String uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public void pauseUnpauseSong() { | ||
sendPostRequest("control/pause", "", System.out::println); | ||
} | ||
|
||
private void sendPostRequest(String url, String body, Consumer<String> callback) { | ||
|
||
HttpRequest request = HttpRequest.newBuilder() | ||
.uri(URI.create("http://localhost:8898/api/" + url)) | ||
.timeout(Duration.ofSeconds(5)) | ||
.header("Content-Type", "application/json") | ||
.POST(BodyPublishers.ofString(body)) | ||
.build(); | ||
client.sendAsync(request, BodyHandlers.ofString()) | ||
.thenApply(HttpResponse::body) | ||
.thenAccept(callback); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.