diff --git a/README.md b/README.md index 14bd418..6e54d85 100644 --- a/README.md +++ b/README.md @@ -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 - Spherical: A densely packed spherical stage that can contain all 400 possible noteblocks -### $toggleMovement +### $toggleMovement \ *aliases: `$movement`* Toggles whether you swing your arm when hitting a noteblock and rotate to look at the noteblocks you are hitting. +### $announcement \ +### $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 \ ### $songItem setSongName \ *aliases: `$item`* diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java b/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java index 312b27e..27b36a5 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java @@ -50,6 +50,7 @@ public class CommandProcessor { commands.add(new toggleFakePlayerCommand()); commands.add(new setStageTypeCommand()); commands.add(new toggleMovementCommand()); + commands.add(new announcementCommand()); commands.add(new songItemCommand()); 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 ", + }; + } + 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 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 { public String getName() { return "songItem"; diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/Config.java b/src/main/java/com/github/hhhzzzsss/songplayer/Config.java index 977d3f0..fab497c 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/Config.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/Config.java @@ -24,6 +24,8 @@ public class Config { public Stage.StageType stageType = Stage.StageType.DEFAULT; public boolean swing = false; public boolean rotate = false; + public boolean doAnnouncement = false; + public String announcementMessage = "&6Now playing: &3[name]"; public static Config getConfig() { if (config == null) { diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java b/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java index 783c75c..cbb5d16 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java @@ -168,6 +168,9 @@ public class SongHandler { currentSong = song; building = true; setCreativeIfNeeded(); + if (Config.getConfig().doAnnouncement) { + sendMessage(Config.getConfig().announcementMessage.replaceAll("\\[name\\]", song.name)); + } if (stage == null) { stage = new Stage(); stage.movePlayerToStagePosition(); @@ -177,6 +180,7 @@ public class SongHandler { } getAndSaveBuildSlot(); SongPlayer.addChatMessage("§6Building noteblocks"); + } private void queueSong(Song song) { @@ -408,14 +412,29 @@ public class SongHandler { private long lastCommandTime = System.currentTimeMillis(); private String cachedCommand = null; + private String cachedMessage = null; private void sendGamemodeCommand(String command) { cachedCommand = command; } + private void sendMessage(String message) { + cachedMessage = message; + } 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); 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() {