forked from ChomeNS/chomens-bot-java
fix some warnings and fix music exception
This commit is contained in:
parent
dcf24f5d18
commit
268f554f4a
12 changed files with 55 additions and 70 deletions
|
@ -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<CompoundTag> future = bot.core().runTracked(String.join(" ", args));
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -33,7 +33,7 @@ public class VoiceChatPlugin extends Bot.Listener {
|
|||
|
||||
private boolean running = false;
|
||||
|
||||
@Getter private List<ClientGroup> groups = new ArrayList<>();
|
||||
@Getter private final List<ClientGroup> groups = new ArrayList<>();
|
||||
|
||||
public VoiceChatPlugin(Bot bot) {
|
||||
this.bot = bot;
|
||||
|
|
|
@ -150,7 +150,7 @@ public class MidiConverter {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Instrument[]> instrumentMap = new HashMap<>();
|
||||
public static final HashMap<Integer, Instrument[]> 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<Integer, Integer> percussionMap = new HashMap<>();
|
||||
public static final HashMap<Integer, Integer> percussionMap = new HashMap<>();
|
||||
static {
|
||||
percussionMap.put(35, 10 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(36, 6 + 25*Instrument.BASEDRUM.id);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -7,8 +7,8 @@ import java.util.Collections;
|
|||
|
||||
// Author: hhhzzzsss & _ChipMC_ but i changed most of the stuff
|
||||
public class Song {
|
||||
public ArrayList<Note> notes = new ArrayList<>();
|
||||
public Component name;
|
||||
public final ArrayList<Note> 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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue