Added announcement command

This commit is contained in:
hhhzzzsss 2023-06-22 01:12:56 -05:00
parent 23c4d27e2c
commit 6c6c04eb47
4 changed files with 87 additions and 3 deletions

View file

@ -113,11 +113,19 @@ Sets the type of noteblock stage to build. Thanks Sk8kman and Lizard16 for the s
- Wide: A cylindrical stage with a maximum of 360 noteblocks - Wide: A cylindrical stage with a maximum of 360 noteblocks
- Spherical: A densely packed spherical stage that can contain all 400 possible noteblocks - Spherical: A densely packed spherical stage that can contain all 400 possible noteblocks
### $toggleMovement <swing | rotate> ### $toggleMovement \<swing | rotate>
*aliases: `$movement`* *aliases: `$movement`*
Toggles whether you swing your arm when hitting a noteblock and rotate to look at the noteblocks you are hitting. Toggles whether you swing your arm when hitting a noteblock and rotate to look at the noteblocks you are hitting.
### $announcement \<enable | disable | getMessage>
### $announcement setMessage
Set an announcement message that is sent when you start playing a song.
With setMessage, write `[name]` where the song name should go.
Example: `$announcement setMessage &6Now playing: &3[name]`
### $songItem create \<song or url> ### $songItem create \<song or url>
### $songItem setSongName \<name> ### $songItem setSongName \<name>
*aliases: `$item`* *aliases: `$item`*

View file

@ -50,6 +50,7 @@ public class CommandProcessor {
commands.add(new toggleFakePlayerCommand()); commands.add(new toggleFakePlayerCommand());
commands.add(new setStageTypeCommand()); commands.add(new setStageTypeCommand());
commands.add(new toggleMovementCommand()); commands.add(new toggleMovementCommand());
commands.add(new announcementCommand());
commands.add(new songItemCommand()); commands.add(new songItemCommand());
commands.add(new testSongCommand()); commands.add(new testSongCommand());
@ -928,6 +929,60 @@ public class CommandProcessor {
} }
} }
private static class announcementCommand extends Command {
public String getName() {
return "announcement";
}
public String[] getSyntax() {
return new String[] {
"enable",
"disable",
"getMessage",
"setMessage <message>",
};
}
public String getDescription() {
return "Set an announcement message that is sent when you start playing a song. With setMessage, write [name] where the song name should go.";
}
public boolean processCommand(String args) {
String[] split = args.split(" ", 2);
switch (split[0].toLowerCase(Locale.ROOT)) {
case "enable":
if (split.length != 1) return false;
Config.getConfig().doAnnouncement = true;
SongPlayer.addChatMessage("§6Enabled song announcements");
Config.saveConfigWithErrorHandling();
return true;
case "disable":
if (split.length != 1) return false;
Config.getConfig().doAnnouncement = false;
SongPlayer.addChatMessage("§6Disabled song announcements");
Config.saveConfigWithErrorHandling();
return true;
case "getmessage":
if (split.length != 1) return false;
SongPlayer.addChatMessage("§6Current announcement message is §r" + Config.getConfig().announcementMessage);
return true;
case "setmessage":
if (split.length != 2) return false;
Config.getConfig().announcementMessage = split[1];
SongPlayer.addChatMessage("§6Set announcement message to §r" + split[1]);
Config.saveConfigWithErrorHandling();
return true;
default:
return false;
}
}
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
if (!args.contains(" ")) {
return CommandSource.suggestMatching(new String[]{"enable", "disable", "getMessage", "setMessage"}, suggestionsBuilder);
}
else {
return null;
}
}
}
private static class songItemCommand extends Command { private static class songItemCommand extends Command {
public String getName() { public String getName() {
return "songItem"; return "songItem";

View file

@ -24,6 +24,8 @@ public class Config {
public Stage.StageType stageType = Stage.StageType.DEFAULT; public Stage.StageType stageType = Stage.StageType.DEFAULT;
public boolean swing = false; public boolean swing = false;
public boolean rotate = false; public boolean rotate = false;
public boolean doAnnouncement = false;
public String announcementMessage = "&6Now playing: &3[name]";
public static Config getConfig() { public static Config getConfig() {
if (config == null) { if (config == null) {

View file

@ -168,6 +168,9 @@ public class SongHandler {
currentSong = song; currentSong = song;
building = true; building = true;
setCreativeIfNeeded(); setCreativeIfNeeded();
if (Config.getConfig().doAnnouncement) {
sendMessage(Config.getConfig().announcementMessage.replaceAll("\\[name\\]", song.name));
}
if (stage == null) { if (stage == null) {
stage = new Stage(); stage = new Stage();
stage.movePlayerToStagePosition(); stage.movePlayerToStagePosition();
@ -177,6 +180,7 @@ public class SongHandler {
} }
getAndSaveBuildSlot(); getAndSaveBuildSlot();
SongPlayer.addChatMessage("§6Building noteblocks"); SongPlayer.addChatMessage("§6Building noteblocks");
} }
private void queueSong(Song song) { private void queueSong(Song song) {
@ -408,14 +412,29 @@ public class SongHandler {
private long lastCommandTime = System.currentTimeMillis(); private long lastCommandTime = System.currentTimeMillis();
private String cachedCommand = null; private String cachedCommand = null;
private String cachedMessage = null;
private void sendGamemodeCommand(String command) { private void sendGamemodeCommand(String command) {
cachedCommand = command; cachedCommand = command;
} }
private void sendMessage(String message) {
cachedMessage = message;
}
private void checkCommandCache() { private void checkCommandCache() {
if (cachedCommand != null && System.currentTimeMillis() >= lastCommandTime + 1500) { long currentTime = System.currentTimeMillis();
if (currentTime >= lastCommandTime + 1500 && cachedCommand != null) {
SongPlayer.MC.getNetworkHandler().sendCommand(cachedCommand); SongPlayer.MC.getNetworkHandler().sendCommand(cachedCommand);
cachedCommand = null; cachedCommand = null;
lastCommandTime = System.currentTimeMillis(); lastCommandTime = currentTime;
}
else if (currentTime >= lastCommandTime + 500 && cachedMessage != null) {
if (cachedMessage.startsWith("/")) {
SongPlayer.MC.getNetworkHandler().sendCommand(cachedMessage.substring(1));
}
else {
SongPlayer.MC.getNetworkHandler().sendChatMessage(cachedMessage);
}
cachedMessage = null;
lastCommandTime = currentTime;
} }
} }
private void setCreativeIfNeeded() { private void setCreativeIfNeeded() {