add all stuff i have made
too lazy to list them lol
This commit is contained in:
parent
8fd31327b4
commit
d3feb98040
8 changed files with 90 additions and 77 deletions
|
@ -53,6 +53,7 @@ public class CommandProcessor {
|
||||||
commands.add(new announcementCommand());
|
commands.add(new announcementCommand());
|
||||||
commands.add(new songItemCommand());
|
commands.add(new songItemCommand());
|
||||||
commands.add(new testSongCommand());
|
commands.add(new testSongCommand());
|
||||||
|
commands.add(new pitchCommand());
|
||||||
|
|
||||||
for (Command command : commands) {
|
for (Command command : commands) {
|
||||||
commandMap.put(command.getName().toLowerCase(Locale.ROOT), command);
|
commandMap.put(command.getName().toLowerCase(Locale.ROOT), command);
|
||||||
|
@ -129,7 +130,7 @@ public class CommandProcessor {
|
||||||
if (args.length() == 0) {
|
if (args.length() == 0) {
|
||||||
StringBuilder helpMessage = new StringBuilder("§6Commands -");
|
StringBuilder helpMessage = new StringBuilder("§6Commands -");
|
||||||
for (Command c : commands) {
|
for (Command c : commands) {
|
||||||
helpMessage.append(" " + Config.getConfig().prefix + c.getName());
|
helpMessage.append(" ").append(Config.getConfig().prefix).append(c.getName());
|
||||||
}
|
}
|
||||||
SongPlayer.addChatMessage(helpMessage.toString());
|
SongPlayer.addChatMessage(helpMessage.toString());
|
||||||
}
|
}
|
||||||
|
@ -239,7 +240,7 @@ public class CommandProcessor {
|
||||||
SongHandler.getInstance().stage.movePlayerToStagePosition();
|
SongHandler.getInstance().stage.movePlayerToStagePosition();
|
||||||
}
|
}
|
||||||
SongHandler.getInstance().restoreStateAndCleanUp();
|
SongHandler.getInstance().restoreStateAndCleanUp();
|
||||||
SongPlayer.addChatMessage("§6Stopped playing");
|
SongPlayer.addChatMessage("§6Stopped playing", true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -293,7 +294,7 @@ public class CommandProcessor {
|
||||||
try {
|
try {
|
||||||
long time = Util.parseTime(args);
|
long time = Util.parseTime(args);
|
||||||
SongHandler.getInstance().currentSong.setTime(time);
|
SongHandler.getInstance().currentSong.setTime(time);
|
||||||
SongPlayer.addChatMessage("§6Set song time to §3" + Util.formatTime(time));
|
SongPlayer.addChatMessage("§6Set song time to §3" + Util.formatTime(time), true);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SongPlayer.addChatMessage("§cNot a valid time stamp");
|
SongPlayer.addChatMessage("§cNot a valid time stamp");
|
||||||
|
@ -325,10 +326,10 @@ public class CommandProcessor {
|
||||||
SongHandler.getInstance().currentSong.looping = !SongHandler.getInstance().currentSong.looping;
|
SongHandler.getInstance().currentSong.looping = !SongHandler.getInstance().currentSong.looping;
|
||||||
SongHandler.getInstance().currentSong.loopCount = 0;
|
SongHandler.getInstance().currentSong.loopCount = 0;
|
||||||
if (SongHandler.getInstance().currentSong.looping) {
|
if (SongHandler.getInstance().currentSong.looping) {
|
||||||
SongPlayer.addChatMessage("§6Enabled looping");
|
SongPlayer.addChatMessage("§6Enabled looping", true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SongPlayer.addChatMessage("§6Disabled looping");
|
SongPlayer.addChatMessage("§6Disabled looping", true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -432,8 +433,8 @@ public class CommandProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> subdirectories = null;
|
List<String> subdirectories;
|
||||||
List<String> songs = null;
|
List<String> songs;
|
||||||
try {
|
try {
|
||||||
subdirectories = Files.list(dir)
|
subdirectories = Files.list(dir)
|
||||||
.filter(Files::isDirectory)
|
.filter(Files::isDirectory)
|
||||||
|
@ -592,9 +593,9 @@ public class CommandProcessor {
|
||||||
Config.getConfig().loopPlaylists = !Config.getConfig().loopPlaylists;
|
Config.getConfig().loopPlaylists = !Config.getConfig().loopPlaylists;
|
||||||
SongHandler.getInstance().setPlaylistLoop(Config.getConfig().loopPlaylists);
|
SongHandler.getInstance().setPlaylistLoop(Config.getConfig().loopPlaylists);
|
||||||
if (Config.getConfig().loopPlaylists) {
|
if (Config.getConfig().loopPlaylists) {
|
||||||
SongPlayer.addChatMessage("§6Enabled playlist looping");
|
SongPlayer.addChatMessage("§6Enabled playlist looping", true);
|
||||||
} else {
|
} else {
|
||||||
SongPlayer.addChatMessage("§6Disabled playlist looping");
|
SongPlayer.addChatMessage("§6Disabled playlist looping", true);
|
||||||
}
|
}
|
||||||
Config.saveConfigWithErrorHandling();
|
Config.saveConfigWithErrorHandling();
|
||||||
return true;
|
return true;
|
||||||
|
@ -604,9 +605,9 @@ public class CommandProcessor {
|
||||||
Config.getConfig().shufflePlaylists = !Config.getConfig().shufflePlaylists;
|
Config.getConfig().shufflePlaylists = !Config.getConfig().shufflePlaylists;
|
||||||
SongHandler.getInstance().setPlaylistShuffle(Config.getConfig().shufflePlaylists);
|
SongHandler.getInstance().setPlaylistShuffle(Config.getConfig().shufflePlaylists);
|
||||||
if (Config.getConfig().shufflePlaylists) {
|
if (Config.getConfig().shufflePlaylists) {
|
||||||
SongPlayer.addChatMessage("§6Enabled playlist shuffling");
|
SongPlayer.addChatMessage("§6Enabled playlist shuffling", true);
|
||||||
} else {
|
} else {
|
||||||
SongPlayer.addChatMessage("§6Disabled playlist shuffling");
|
SongPlayer.addChatMessage("§6Disabled playlist shuffling", true);
|
||||||
}
|
}
|
||||||
Config.saveConfigWithErrorHandling();
|
Config.saveConfigWithErrorHandling();
|
||||||
return true;
|
return true;
|
||||||
|
@ -685,7 +686,7 @@ public class CommandProcessor {
|
||||||
if (playlistFiles == null) {
|
if (playlistFiles == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int max = playlistFiles.collect(Collectors.toList()).size();
|
int max = (int) playlistFiles.count();
|
||||||
Stream<String> suggestions = IntStream.range(1, max+1).mapToObj(Integer::toString);
|
Stream<String> suggestions = IntStream.range(1, max+1).mapToObj(Integer::toString);
|
||||||
return CommandSource.suggestMatching(suggestions, suggestionsBuilder);
|
return CommandSource.suggestMatching(suggestions, suggestionsBuilder);
|
||||||
}
|
}
|
||||||
|
@ -858,7 +859,7 @@ public class CommandProcessor {
|
||||||
try {
|
try {
|
||||||
Stage.StageType stageType = Stage.StageType.valueOf(args.toUpperCase(Locale.ROOT));
|
Stage.StageType stageType = Stage.StageType.valueOf(args.toUpperCase(Locale.ROOT));
|
||||||
Config.getConfig().stageType = stageType;
|
Config.getConfig().stageType = stageType;
|
||||||
SongPlayer.addChatMessage("§6Set stage type to §3" + stageType.name());
|
SongPlayer.addChatMessage("§6Set stage type to §3" + stageType.name(), true);
|
||||||
Config.saveConfigWithErrorHandling();
|
Config.saveConfigWithErrorHandling();
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
|
@ -936,13 +937,11 @@ public class CommandProcessor {
|
||||||
public String[] getSyntax() {
|
public String[] getSyntax() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
"enable",
|
"enable",
|
||||||
"disable",
|
"disable"
|
||||||
"getMessage",
|
|
||||||
"setMessage <message>",
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public String getDescription() {
|
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.";
|
return "Set an announcement message that is sent when you start playing a song.";
|
||||||
}
|
}
|
||||||
public boolean processCommand(String args) {
|
public boolean processCommand(String args) {
|
||||||
String[] split = args.split(" ", 2);
|
String[] split = args.split(" ", 2);
|
||||||
|
@ -950,23 +949,13 @@ public class CommandProcessor {
|
||||||
case "enable":
|
case "enable":
|
||||||
if (split.length != 1) return false;
|
if (split.length != 1) return false;
|
||||||
Config.getConfig().doAnnouncement = true;
|
Config.getConfig().doAnnouncement = true;
|
||||||
SongPlayer.addChatMessage("§6Enabled song announcements");
|
SongPlayer.addChatMessage("§6Enabled song announcements", true);
|
||||||
Config.saveConfigWithErrorHandling();
|
Config.saveConfigWithErrorHandling();
|
||||||
return true;
|
return true;
|
||||||
case "disable":
|
case "disable":
|
||||||
if (split.length != 1) return false;
|
if (split.length != 1) return false;
|
||||||
Config.getConfig().doAnnouncement = false;
|
Config.getConfig().doAnnouncement = false;
|
||||||
SongPlayer.addChatMessage("§6Disabled song announcements");
|
SongPlayer.addChatMessage("§6Disabled song announcements", true);
|
||||||
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();
|
Config.saveConfigWithErrorHandling();
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
|
@ -975,7 +964,7 @@ public class CommandProcessor {
|
||||||
}
|
}
|
||||||
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
|
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
|
||||||
if (!args.contains(" ")) {
|
if (!args.contains(" ")) {
|
||||||
return CommandSource.suggestMatching(new String[]{"enable", "disable", "getMessage", "setMessage"}, suggestionsBuilder);
|
return CommandSource.suggestMatching(new String[]{"enable", "disable"}, suggestionsBuilder);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -1087,6 +1076,25 @@ public class CommandProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class pitchCommand extends Command {
|
||||||
|
public String getName() { return "pitch"; }
|
||||||
|
public String[] getSyntax() { return new String[] { "<pitch>" }; }
|
||||||
|
public String getDescription() { return "Sets the pitch of the song"; }
|
||||||
|
public boolean processCommand(String args) {
|
||||||
|
if (args.length() == 0) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
SongHandler.getInstance().pitch = Integer.parseInt(args);
|
||||||
|
|
||||||
|
SongPlayer.addChatMessage("§6Set the pitch to §3" + args, true);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static CompletableFuture<Suggestions> handleSuggestions(String text, SuggestionsBuilder suggestionsBuilder) {
|
public static CompletableFuture<Suggestions> handleSuggestions(String text, SuggestionsBuilder suggestionsBuilder) {
|
||||||
if (!text.contains(" ")) {
|
if (!text.contains(" ")) {
|
||||||
List<String> names = commandCompletions
|
List<String> names = commandCompletions
|
||||||
|
|
|
@ -25,7 +25,6 @@ public class Config {
|
||||||
public boolean swing = false;
|
public boolean swing = false;
|
||||||
public boolean rotate = false;
|
public boolean rotate = false;
|
||||||
public boolean doAnnouncement = 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) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.github.hhhzzzsss.songplayer;
|
package com.github.hhhzzzsss.songplayer;
|
||||||
|
|
||||||
|
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
|
@ -35,12 +36,18 @@ public class SongPlayer implements ModInitializer {
|
||||||
CommandProcessor.initCommands();
|
CommandProcessor.initCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addChatMessage(String message) {
|
public static void addChatMessage(String message) { addChatMessage(message, false); }
|
||||||
MC.player.sendMessage(Text.of(message), false);
|
public static void addChatMessage(String message, boolean broadcast) {
|
||||||
|
MC.player.sendMessage(Text.literal(message), false);
|
||||||
|
|
||||||
|
if (broadcast && Config.getConfig().doAnnouncement) SongHandler.getInstance().sendMessage(message.replace('§', '&'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addChatMessage(Text text) {
|
public static void addChatMessage(Text text) { addChatMessage(text, false); }
|
||||||
|
public static void addChatMessage(Text text, boolean broadcast) {
|
||||||
MC.player.sendMessage(text, false);
|
MC.player.sendMessage(text, false);
|
||||||
|
|
||||||
|
if (broadcast && Config.getConfig().doAnnouncement) SongHandler.getInstance().sendMessage(text.getString().replace('§', '&')); // Maybe parse the colors
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeFakePlayer() {
|
public static void removeFakePlayer() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.github.hhhzzzsss.songplayer.conversion;
|
package com.github.hhhzzzsss.songplayer.conversion;
|
||||||
|
|
||||||
|
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
|
||||||
import com.github.hhhzzzsss.songplayer.song.DownloadUtils;
|
import com.github.hhhzzzsss.songplayer.song.DownloadUtils;
|
||||||
import com.github.hhhzzzsss.songplayer.song.Instrument;
|
import com.github.hhhzzzsss.songplayer.song.Instrument;
|
||||||
import com.github.hhhzzzsss.songplayer.song.Note;
|
import com.github.hhhzzzsss.songplayer.song.Note;
|
||||||
|
@ -25,7 +26,7 @@ public class MidiConverter {
|
||||||
public static final int NOTE_OFF = 0x80;
|
public static final int NOTE_OFF = 0x80;
|
||||||
|
|
||||||
public static Song getSongFromUrl(URL url) throws IOException, InvalidMidiDataException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException {
|
public static Song getSongFromUrl(URL url) throws IOException, InvalidMidiDataException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException {
|
||||||
Sequence sequence = MidiSystem.getSequence(DownloadUtils.DownloadToInputStream(url, 5*1024*1024));
|
Sequence sequence = MidiSystem.getSequence(DownloadUtils.DownloadToInputStream(url));
|
||||||
return getSong(sequence, Paths.get(url.toURI().getPath()).getFileName().toString());
|
return getSong(sequence, Paths.get(url.toURI().getPath()).getFileName().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +147,7 @@ public class MidiConverter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pitch = midiPitch-instrument.offset;
|
int pitch = (midiPitch-instrument.offset) + SongHandler.getInstance().pitch;
|
||||||
int noteId = pitch + instrument.instrumentId*25;
|
int noteId = pitch + instrument.instrumentId*25;
|
||||||
long time = microTime / 1000L;
|
long time = microTime / 1000L;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.github.hhhzzzsss.songplayer.conversion;
|
package com.github.hhhzzzsss.songplayer.conversion;
|
||||||
|
|
||||||
|
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
|
||||||
import com.github.hhhzzzsss.songplayer.song.Instrument;
|
import com.github.hhhzzzsss.songplayer.song.Instrument;
|
||||||
import com.github.hhhzzzsss.songplayer.song.Note;
|
import com.github.hhhzzzsss.songplayer.song.Note;
|
||||||
import com.github.hhhzzzsss.songplayer.song.Song;
|
import com.github.hhhzzzsss.songplayer.song.Song;
|
||||||
|
@ -147,17 +148,18 @@ public class NBSConverter {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (note.key < 33 || note.key > 57) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte layerVolume = 100;
|
byte layerVolume = 100;
|
||||||
if (nbsLayers.size() > note.layer) {
|
if (nbsLayers.size() > note.layer) {
|
||||||
layerVolume = nbsLayers.get(note.layer).volume;
|
layerVolume = nbsLayers.get(note.layer).volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pitch = note.key-33;
|
int key = note.key;
|
||||||
int noteId = pitch + instrument.instrumentId*25;
|
|
||||||
|
while (key < 33) key += 12;
|
||||||
|
while (key > 57) key -= 12;
|
||||||
|
|
||||||
|
int pitch = key-33;
|
||||||
|
int noteId = (pitch + instrument.instrumentId*25) + SongHandler.getInstance().pitch;
|
||||||
song.add(new Note(noteId, getMilliTime(note.tick, tempo)));
|
song.add(new Note(noteId, getMilliTime(note.tick, tempo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,9 @@ import net.minecraft.world.GameMode;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class SongHandler {
|
public class SongHandler {
|
||||||
private static SongHandler instance = null;
|
private static SongHandler instance = null;
|
||||||
|
@ -47,6 +49,8 @@ public class SongHandler {
|
||||||
public boolean wasFlying = false;
|
public boolean wasFlying = false;
|
||||||
public GameMode originalGamemode = GameMode.CREATIVE;
|
public GameMode originalGamemode = GameMode.CREATIVE;
|
||||||
|
|
||||||
|
public int pitch = 0;
|
||||||
|
|
||||||
boolean playlistChecked = false;
|
boolean playlistChecked = false;
|
||||||
|
|
||||||
public void onUpdate(boolean tick) {
|
public void onUpdate(boolean tick) {
|
||||||
|
@ -81,7 +85,7 @@ public class SongHandler {
|
||||||
// Check if loader thread is finished and handle accordingly
|
// Check if loader thread is finished and handle accordingly
|
||||||
if (loaderThread != null && !loaderThread.isAlive()) {
|
if (loaderThread != null && !loaderThread.isAlive()) {
|
||||||
if (loaderThread.exception != null) {
|
if (loaderThread.exception != null) {
|
||||||
SongPlayer.addChatMessage("§cFailed to load song: §4" + loaderThread.exception.getMessage());
|
SongPlayer.addChatMessage("§cFailed to load song: §4" + loaderThread.exception.getMessage(), true);
|
||||||
} else {
|
} else {
|
||||||
if (currentSong == null) {
|
if (currentSong == null) {
|
||||||
setSong(loaderThread.song);
|
setSong(loaderThread.song);
|
||||||
|
@ -144,10 +148,10 @@ public class SongHandler {
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
loaderThread = new SongLoaderThread(location);
|
loaderThread = new SongLoaderThread(location);
|
||||||
SongPlayer.addChatMessage("§6Loading §3" + location);
|
SongPlayer.addChatMessage("§6Loading §3" + location, true);
|
||||||
loaderThread.start();
|
loaderThread.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SongPlayer.addChatMessage("§cFailed to load song: §4" + e.getMessage());
|
SongPlayer.addChatMessage("§cFailed to load song: §4" + e.getMessage(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,9 +172,6 @@ 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();
|
||||||
|
@ -179,13 +180,13 @@ public class SongHandler {
|
||||||
stage.sendMovementPacketToStagePosition();
|
stage.sendMovementPacketToStagePosition();
|
||||||
}
|
}
|
||||||
getAndSaveBuildSlot();
|
getAndSaveBuildSlot();
|
||||||
SongPlayer.addChatMessage("§6Building noteblocks");
|
SongPlayer.addChatMessage("§6Building noteblocks", true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queueSong(Song song) {
|
private void queueSong(Song song) {
|
||||||
songQueue.add(song);
|
songQueue.add(song);
|
||||||
SongPlayer.addChatMessage("§6Added song to queue: §3" + song.name);
|
SongPlayer.addChatMessage("§6Added song to queue: §3" + song.name, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlaylist(Path playlist) {
|
public void setPlaylist(Path playlist) {
|
||||||
|
@ -270,7 +271,7 @@ public class SongHandler {
|
||||||
building = false;
|
building = false;
|
||||||
setSurvivalIfNeeded();
|
setSurvivalIfNeeded();
|
||||||
stage.sendMovementPacketToStagePosition();
|
stage.sendMovementPacketToStagePosition();
|
||||||
SongPlayer.addChatMessage("§6Now playing §3" + currentSong.name);
|
SongPlayer.addChatMessage("§6Now playing §3" + currentSong.name, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void setBuildProgressDisplay() {
|
private void setBuildProgressDisplay() {
|
||||||
|
@ -321,7 +322,7 @@ public class SongHandler {
|
||||||
System.out.println("Missing note: " + Instrument.getInstrumentFromId(instrumentId).name() + ":" + pitch);
|
System.out.println("Missing note: " + Instrument.getInstrumentFromId(instrumentId).name() + ":" + pitch);
|
||||||
}
|
}
|
||||||
getAndSaveBuildSlot();
|
getAndSaveBuildSlot();
|
||||||
SongPlayer.addChatMessage("§6Stage was altered. Rebuilding!");
|
SongPlayer.addChatMessage("§6Stage was altered. Rebuilding!", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -343,7 +344,7 @@ public class SongHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentSong.finished()) {
|
if (currentSong.finished()) {
|
||||||
SongPlayer.addChatMessage("§6Done playing §3" + currentSong.name);
|
SongPlayer.addChatMessage("§6Done playing §3" + currentSong.name, true);
|
||||||
currentSong = null;
|
currentSong = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,40 +412,40 @@ public class SongHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private long lastCommandTime = System.currentTimeMillis();
|
private long lastCommandTime = System.currentTimeMillis();
|
||||||
private String cachedCommand = null;
|
private List<String> cachedCommands = new ArrayList<>();
|
||||||
private String cachedMessage = null;
|
private List<String> cachedMessages = new ArrayList<>();
|
||||||
private void sendGamemodeCommand(String command) {
|
private void sendGamemodeCommand(String command) {
|
||||||
cachedCommand = command;
|
cachedCommands.add(command);
|
||||||
}
|
}
|
||||||
private void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
cachedMessage = message;
|
cachedMessages.add(message);
|
||||||
}
|
}
|
||||||
private void checkCommandCache() {
|
private void checkCommandCache() {
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
if (currentTime >= lastCommandTime + 1500 && cachedCommand != null) {
|
if (currentTime >= lastCommandTime + 1500 && !cachedCommands.isEmpty()) {
|
||||||
SongPlayer.MC.getNetworkHandler().sendCommand(cachedCommand);
|
SongPlayer.MC.getNetworkHandler().sendCommand(cachedCommands.get(0));
|
||||||
cachedCommand = null;
|
cachedCommands.remove(0);
|
||||||
lastCommandTime = currentTime;
|
lastCommandTime = currentTime;
|
||||||
}
|
}
|
||||||
else if (currentTime >= lastCommandTime + 500 && cachedMessage != null) {
|
else if (currentTime >= lastCommandTime + 500 && !cachedMessages.isEmpty()) {
|
||||||
if (cachedMessage.startsWith("/")) {
|
if (cachedMessages.get(0).startsWith("/")) {
|
||||||
SongPlayer.MC.getNetworkHandler().sendCommand(cachedMessage.substring(1));
|
SongPlayer.MC.getNetworkHandler().sendCommand(cachedMessages.get(0).substring(1));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SongPlayer.MC.getNetworkHandler().sendChatMessage(cachedMessage);
|
SongPlayer.MC.getNetworkHandler().sendChatMessage(cachedMessages.get(0));
|
||||||
}
|
}
|
||||||
cachedMessage = null;
|
cachedMessages.remove(0);
|
||||||
lastCommandTime = currentTime;
|
lastCommandTime = currentTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void setCreativeIfNeeded() {
|
private void setCreativeIfNeeded() {
|
||||||
cachedCommand = null;
|
cachedCommands.clear();
|
||||||
if (SongPlayer.MC.interactionManager.getCurrentGameMode() != GameMode.CREATIVE) {
|
if (SongPlayer.MC.interactionManager.getCurrentGameMode() != GameMode.CREATIVE) {
|
||||||
sendGamemodeCommand(Config.getConfig().creativeCommand);
|
sendGamemodeCommand(Config.getConfig().creativeCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void setSurvivalIfNeeded() {
|
private void setSurvivalIfNeeded() {
|
||||||
cachedCommand = null;
|
cachedCommands.clear();
|
||||||
if (SongPlayer.MC.interactionManager.getCurrentGameMode() != GameMode.SURVIVAL) {
|
if (SongPlayer.MC.interactionManager.getCurrentGameMode() != GameMode.SURVIVAL) {
|
||||||
sendGamemodeCommand(Config.getConfig().survivalCommand);
|
sendGamemodeCommand(Config.getConfig().survivalCommand);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class DownloadUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] DownloadToByteArray(URL url, int maxSize) throws IOException, KeyManagementException, NoSuchAlgorithmException {
|
public static byte[] DownloadToByteArray(URL url) throws IOException, KeyManagementException, NoSuchAlgorithmException {
|
||||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||||
ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom());
|
ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom());
|
||||||
SSLContext.setDefault(ctx);
|
SSLContext.setDefault(ctx);
|
||||||
|
@ -43,13 +43,8 @@ public class DownloadUtils {
|
||||||
try {
|
try {
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
int n;
|
int n;
|
||||||
int tot = 0;
|
|
||||||
while ((n = downloadStream.read(buf)) > 0) {
|
while ((n = downloadStream.read(buf)) > 0) {
|
||||||
byteArrayStream.write(buf, 0, n);
|
byteArrayStream.write(buf, 0, n);
|
||||||
tot += n;
|
|
||||||
if (tot > maxSize) {
|
|
||||||
throw new IOException("File is too large");
|
|
||||||
}
|
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +56,7 @@ public class DownloadUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputStream DownloadToInputStream(URL url, int maxSize) throws KeyManagementException, NoSuchAlgorithmException, IOException {
|
public static InputStream DownloadToInputStream(URL url) throws KeyManagementException, NoSuchAlgorithmException, IOException {
|
||||||
return new ByteArrayInputStream(DownloadToByteArray(url, maxSize));
|
return new ByteArrayInputStream(DownloadToByteArray(url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class SongLoaderThread extends Thread{
|
||||||
try {
|
try {
|
||||||
byte[] bytes;
|
byte[] bytes;
|
||||||
if (isUrl) {
|
if (isUrl) {
|
||||||
bytes = DownloadUtils.DownloadToByteArray(songUrl, 10*1024*1024);
|
bytes = DownloadUtils.DownloadToByteArray(songUrl);
|
||||||
filename = Paths.get(songUrl.toURI().getPath()).getFileName().toString();
|
filename = Paths.get(songUrl.toURI().getPath()).getFileName().toString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue