diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CommandBlockCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CommandBlockCommand.java index 0f1f00a..7eb8fd9 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CommandBlockCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CommandBlockCommand.java @@ -42,7 +42,7 @@ public class CommandBlockCommand implements Command { return TrustLevel.PUBLIC; } - public Component execute(CommandContext context, String[] args, String[] fullArgs) throws ExecutionException, InterruptedException { + public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); final CompletableFuture future = bot.core().runTracked(String.join(" ", args)); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/data/BotBossBar.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/data/BotBossBar.java index e8cb215..c18cc40 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/data/BotBossBar.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/data/BotBossBar.java @@ -12,7 +12,7 @@ import java.util.UUID; public class BotBossBar extends BossBar { public UUID uuid = UUID.randomUUID(); // the random uuid will be temporary - public Component secret = Component.text(Math.random() * 69420); + public final Component secret = Component.text(Math.random() * 69420); private final Bot bot; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/data/Mail.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/data/Mail.java index 348c878..a124a54 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/data/Mail.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/data/Mail.java @@ -2,7 +2,6 @@ package land.chipmunk.chayapak.chomens_bot.data; import lombok.AllArgsConstructor; import lombok.Getter; -import org.joda.time.DateTime; @AllArgsConstructor public class Mail { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java index 5938d46..66fe72f 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java @@ -25,7 +25,7 @@ public class MusicPlayerPlugin extends Bot.Listener { private final Bot bot; public static final String SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic]"; - public static File SONG_DIR = new File("songs"); + public static final File SONG_DIR = new File("songs"); static { if (!SONG_DIR.exists()) SONG_DIR.mkdir(); } @@ -52,44 +52,33 @@ public class MusicPlayerPlugin extends Bot.Listener { } public void loadSong (Path location) { - try { - final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot); + final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot); - bot.chat().tellraw( - Component - .translatable( - "Loading %s", - Component.text(location.getFileName().toString(), ColorUtilities.getColorByString(bot.config().colorPalette().secondary())) - ) - .color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor())) - ); + bot.chat().tellraw( + Component + .translatable( + "Loading %s", + Component.text(location.getFileName().toString(), ColorUtilities.getColorByString(bot.config().colorPalette().secondary())) + ) + .color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor())) + ); - bot.executorService().submit(runnable); - } catch (SongLoaderException e) { - e.printStackTrace(); - bot.chat().tellraw(Component.translatable("Failed to load song: %s", e.message()).color(NamedTextColor.RED)); - loaderThread = null; - } + bot.executorService().submit(runnable); } public void loadSong (URL location) { - try { - final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot); + final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot); - bot.chat().tellraw( - Component - .translatable( - "Loading %s", - Component.text(location.toString(), ColorUtilities.getColorByString(bot.config().colorPalette().secondary())) - ) - .color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor())) - ); + bot.chat().tellraw( + Component + .translatable( + "Loading %s", + Component.text(location.toString(), ColorUtilities.getColorByString(bot.config().colorPalette().secondary())) + ) + .color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor())) + ); - bot.executorService().submit(runnable); - } catch (SongLoaderException e) { - bot.chat().tellraw(Component.translatable("Failed to load song: %s", e.message()).color(NamedTextColor.RED)); - loaderThread = null; - } + bot.executorService().submit(runnable); } public void coreReady () { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/VoiceChatPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/VoiceChatPlugin.java index 70f7151..9545efa 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/VoiceChatPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/VoiceChatPlugin.java @@ -33,7 +33,7 @@ public class VoiceChatPlugin extends Bot.Listener { private boolean running = false; - @Getter private List groups = new ArrayList<>(); + @Getter private final List groups = new ArrayList<>(); public VoiceChatPlugin(Bot bot) { this.bot = bot; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java index 97a0ffa..0316b8b 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java @@ -150,7 +150,7 @@ public class MidiConverter { return null; } - public static HashMap instrumentMap = new HashMap<>(); + public static final HashMap instrumentMap = new HashMap<>(); static { // Piano (HARP BASS BELL) instrumentMap.put(0, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Acoustic Grand Piano @@ -303,7 +303,7 @@ public class MidiConverter { instrumentMap.put(119, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); } - public static HashMap percussionMap = new HashMap<>(); + public static final HashMap percussionMap = new HashMap<>(); static { percussionMap.put(35, 10 + 25*Instrument.BASEDRUM.id); percussionMap.put(36, 6 + 25*Instrument.BASEDRUM.id); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java index 1969369..cf0d8b9 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java @@ -9,7 +9,7 @@ import java.util.ArrayList; // Author: hhhzzzsss public class NBSConverter { - public static Instrument[] instrumentIndex = new Instrument[] { + public static final Instrument[] instrumentIndex = new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BASEDRUM, diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Song.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Song.java index f5bb7c8..637f3cc 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Song.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Song.java @@ -7,8 +7,8 @@ import java.util.Collections; // Author: hhhzzzsss & _ChipMC_ but i changed most of the stuff public class Song { - public ArrayList notes = new ArrayList<>(); - public Component name; + public final ArrayList notes = new ArrayList<>(); + public final Component name; public int position = 0; // Current note index public boolean paused = true; public long startTime = 0; // Start time in millis since unix epoch @@ -16,12 +16,12 @@ public class Song { public long time = 0; // Time since start of song public long loopPosition = 200; // Milliseconds into the song to start looping - public String songName; - public String songAuthor; - public String songOriginalAuthor; - public String songDescription; + public final String songName; + public final String songAuthor; + public final String songOriginalAuthor; + public final String songDescription; - public boolean nbs; + public final boolean nbs; // public int loopCount = 0; // Number of times to loop // public int currentLoop = 0; // Number of loops so far diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java index 440a9ae..9f771c8 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java @@ -1,7 +1,6 @@ package land.chipmunk.chayapak.chomens_bot.song; import land.chipmunk.chayapak.chomens_bot.Bot; -import land.chipmunk.chayapak.chomens_bot.plugins.MusicPlayerPlugin; import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; import land.chipmunk.chayapak.chomens_bot.util.DownloadUtilities; import net.kyori.adventure.text.Component; @@ -16,7 +15,7 @@ import java.nio.file.Paths; // Author: _ChipMC_ or hhhzzzsss? also i modified it to use runnable // because thread = bad !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! public class SongLoaderRunnable implements Runnable { - public String fileName; + public final String fileName; private File songPath; private URL songUrl; @@ -27,7 +26,7 @@ public class SongLoaderRunnable implements Runnable { private final boolean isUrl; - public SongLoaderRunnable(URL location, Bot bot) throws SongLoaderException { + public SongLoaderRunnable(URL location, Bot bot) { this.bot = bot; isUrl = true; songUrl = location; @@ -35,7 +34,7 @@ public class SongLoaderRunnable implements Runnable { fileName = location.getFile(); } - public SongLoaderRunnable(Path location, Bot bot) throws SongLoaderException { + public SongLoaderRunnable(Path location, Bot bot) { this.bot = bot; isUrl = false; songPath = location.toFile(); @@ -55,9 +54,9 @@ public class SongLoaderRunnable implements Runnable { name = songPath.getName(); } } catch (Exception e) { - e.printStackTrace(); + exception = new SongLoaderException(Component.text(e.getMessage())); - showFailedMessage(); + failed(); return; } @@ -79,7 +78,7 @@ public class SongLoaderRunnable implements Runnable { if (song == null) { exception = new SongLoaderException(Component.translatable("Invalid format")); - showFailedMessage(); + failed(); } else { bot.music().songQueue().add(song); bot.chat().tellraw( @@ -91,7 +90,9 @@ public class SongLoaderRunnable implements Runnable { } } - private void showFailedMessage () { + private void failed() { + exception.printStackTrace(); bot.chat().tellraw(Component.translatable("Failed to load song: %s", exception.message()).color(NamedTextColor.RED)); + bot.music().loaderThread(null); } } \ No newline at end of file diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ComponentUtilities.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ComponentUtilities.java index 20d9526..dcc8d7f 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ComponentUtilities.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ComponentUtilities.java @@ -11,7 +11,6 @@ import net.kyori.adventure.text.SelectorComponent; import net.kyori.adventure.text.KeybindComponent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.BufferedReader; import java.io.InputStream; @@ -176,23 +175,20 @@ public class ComponentUtilities { } else if (ansi) { String ansiCode = ansiMap.get(code); if (ansiCode == null) { - // will using string builders use less memory or does nothing? - final StringBuilder builder = new StringBuilder(); - builder.append("\u001b[38;2;"); - builder.append(color.red()); - builder.append(";"); - builder.append(color.green()); - builder.append(";"); - builder.append(color.blue()); - builder.append("m"); - - ansiCode = builder.toString(); + ansiCode = "\u001b[38;2;" + + color.red() + + ";" + + color.green() + + ";" + + color.blue() + + "m"; } return ansiCode; } else return null; } + @SuppressWarnings("UnnecessaryUnicodeEscape") public static PartiallyStringifiedOutput stringifyPartially (TextComponent message, boolean motd, boolean ansi, String lastColor) { if (motd || ansi) { final String color = getColor(message.color(), motd, ansi); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/FileLoggerUtilities.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/FileLoggerUtilities.java index 913ef62..73ba71a 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/FileLoggerUtilities.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/FileLoggerUtilities.java @@ -14,8 +14,8 @@ import java.util.zip.GZIPOutputStream; // totallynotskidded™ from HBot public class FileLoggerUtilities { - public static File logDir = new File("logs"); - public static File logFile = new File(logDir, "log.txt"); + public static final File logDir = new File("logs"); + public static final File logFile = new File(logDir, "log.txt"); public static OutputStreamWriter logWriter; public static LocalDate currentLogDate; @@ -24,7 +24,7 @@ public class FileLoggerUtilities { public static String prevEntry = ""; public static int duplicateCounter = 1; - public static ScheduledExecutorService executor = Main.executor; + public static final ScheduledExecutorService executor = Main.executor; public static int spamLevel = 0; public static long freezeTime = 0; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/PersistentDataUtilities.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/PersistentDataUtilities.java index 7b13963..f7659af 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/PersistentDataUtilities.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/PersistentDataUtilities.java @@ -7,7 +7,7 @@ import com.google.gson.JsonObject; import java.io.*; public class PersistentDataUtilities { - public static File file = new File("persistent.json"); + public static final File file = new File("persistent.json"); private static FileWriter writer;