forked from ChomeNS/chomens-bot-java
fix most warnings
This commit is contained in:
parent
a4bbcd4b83
commit
6529fd8004
31 changed files with 41 additions and 124 deletions
|
@ -31,6 +31,9 @@ public class Main {
|
|||
if (!file.exists()) {
|
||||
// creates config file from default-config.yml
|
||||
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("default-config.yml");
|
||||
|
||||
if (is == null) System.exit(1);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
while (reader.ready()) {
|
||||
|
|
|
@ -11,9 +11,7 @@ import net.kyori.adventure.text.TextComponent;
|
|||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class KaboomChatParser implements ChatParser {
|
||||
|
@ -47,8 +45,6 @@ public class KaboomChatParser implements ChatParser {
|
|||
|
||||
if (!message.content().equals("") || !message.style().equals(empty) || children.size() < 3) return null;
|
||||
|
||||
final Map<String, Component> parameters = new HashMap<>();
|
||||
|
||||
final Component prefix = children.get(0);
|
||||
Component displayName = Component.empty();
|
||||
Component contents = Component.empty();
|
||||
|
|
|
@ -7,7 +7,6 @@ import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
|||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CowsayCommand implements Command {
|
||||
|
|
|
@ -6,7 +6,6 @@ import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
|||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -28,7 +28,7 @@ public class MusicCommand implements Command {
|
|||
public String name() { return "music"; }
|
||||
|
||||
public String description() {
|
||||
return "Plays music";
|
||||
return "Play musics";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
|
@ -119,6 +119,8 @@ public class MusicCommand implements Command {
|
|||
} else {
|
||||
final String[] songs = root.toFile().list();
|
||||
|
||||
if (songs == null) return null;
|
||||
|
||||
final String file = Arrays.stream(songs)
|
||||
.filter(song -> song.toLowerCase().contains(_path.toLowerCase()))
|
||||
.toArray(String[]::new)[0];
|
||||
|
|
|
@ -13,7 +13,7 @@ public class RefillCoreCommand implements Command {
|
|||
public String name() { return "refillcore"; }
|
||||
|
||||
public String description() {
|
||||
return "Refills and resets the bot's command core";
|
||||
return "Refills and resets the bots command core";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
|
|
|
@ -6,7 +6,6 @@ import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
|||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -17,7 +17,7 @@ public class UptimeCommand implements Command {
|
|||
public String name() { return "uptime"; }
|
||||
|
||||
public String description() {
|
||||
return "Shows the bot's uptime";
|
||||
return "Shows the bots uptime";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class CommandLoop {
|
||||
@Getter
|
||||
private String command;
|
||||
@Getter
|
||||
private int interval;
|
||||
|
||||
public CommandLoop (String command, int interval) {
|
||||
this.command = command;
|
||||
this.interval = interval;
|
||||
}
|
||||
@Getter private String command;
|
||||
@Getter private int interval;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,11 @@ package land.chipmunk.chayapak.chomens_bot.data;
|
|||
import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Team {
|
||||
@Getter @Setter private String teamName;
|
||||
|
|
|
@ -3,5 +3,5 @@ package land.chipmunk.chayapak.chomens_bot.data.voiceChat;
|
|||
public enum Codec {
|
||||
VOIP,
|
||||
AUDIO,
|
||||
RESTRICTED_LOWDELAY;
|
||||
RESTRICTED_LOWDELAY
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class BossbarManagerPlugin extends Bot.Listener {
|
|||
}
|
||||
|
||||
// is there any way instead of using random?
|
||||
bot.core().run("minecraft:data modify entity @e[tag=" + textDisplayPrefix + name + ",limit=1,sort=random] text set value '" + stringifiedComponent.replace("'", "\\\'") + "'");
|
||||
bot.core().run("minecraft:data modify entity @e[tag=" + textDisplayPrefix + name + ",limit=1,sort=random] text set value '" + stringifiedComponent.replace("'", "\\'") + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import land.chipmunk.chayapak.chomens_bot.commands.*;
|
|||
import land.chipmunk.chayapak.chomens_bot.util.ExceptionUtilities;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -118,7 +119,11 @@ public class CommandHandlerPlugin {
|
|||
|
||||
if (command.trustLevel() != TrustLevel.PUBLIC && !console) {
|
||||
if (discord) {
|
||||
final List<Role> roles = event.getMember().getRoles();
|
||||
final Member member = event.getMember();
|
||||
|
||||
if (member == null) return null;
|
||||
|
||||
final List<Role> roles = member.getRoles();
|
||||
|
||||
final String trustedRoleName = bot.config().discord().trustedRoleName();
|
||||
final String adminRoleName = bot.config().discord().adminRoleName();
|
||||
|
|
|
@ -311,6 +311,12 @@ public class DiscordPlugin {
|
|||
public void sendMessageInstantly (String message, String channelId) {
|
||||
if (jda == null) return;
|
||||
final TextChannel logChannel = jda.getTextChannelById(channelId);
|
||||
|
||||
if (logChannel == null) {
|
||||
System.out.println("Log channel for " + channelId + " is null");
|
||||
return;
|
||||
}
|
||||
|
||||
logChannel.sendMessage(message).queue(
|
||||
(msg) -> doneSendingInLogs.put(channelId, true),
|
||||
(err) -> doneSendingInLogs.put(channelId, false)
|
||||
|
|
|
@ -43,6 +43,8 @@ public class FilterPlugin extends PlayersPlugin.Listener {
|
|||
}
|
||||
}
|
||||
|
||||
if (pattern == null) break;
|
||||
|
||||
if (pattern.matcher(name).find()) {
|
||||
filteredPlayer = _filteredPlayer;
|
||||
break;
|
||||
|
|
|
@ -27,9 +27,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
public static final String SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic]";
|
||||
public static File SONG_DIR = new File("songs");
|
||||
static {
|
||||
if (!SONG_DIR.exists()) {
|
||||
SONG_DIR.mkdir();
|
||||
}
|
||||
if (!SONG_DIR.exists()) SONG_DIR.mkdir();
|
||||
}
|
||||
|
||||
@Getter @Setter private Song currentSong;
|
||||
|
|
|
@ -74,8 +74,4 @@ public class TeamPlugin extends Bot.Listener {
|
|||
}
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
public Team getTeamByUsername (String username) {
|
||||
return teamsByPlayer.get(username);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,10 +53,6 @@ public class TrustedPlugin extends PlayersPlugin.Listener {
|
|||
|
||||
public void broadcast (Component message) { broadcast(message, null); }
|
||||
|
||||
// these can be used in servereval
|
||||
public void broadcast (String message) { broadcast(Component.text(message), null); }
|
||||
public void broadcast (String message, UUID exceptTarget) { broadcast(Component.text(message), exceptTarget); }
|
||||
|
||||
@Override
|
||||
public void playerJoined (MutablePlayerListEntry target) {
|
||||
if (!list.contains(target.profile().getName())) return;
|
||||
|
|
|
@ -23,7 +23,6 @@ public class VoiceChatPlugin extends Bot.Listener {
|
|||
|
||||
private InitializationData initializationData;
|
||||
private ClientVoiceChatSocket socket;
|
||||
private InetAddress address;
|
||||
private InetSocketAddress socketAddress;
|
||||
|
||||
private boolean running = false;
|
||||
|
@ -70,7 +69,7 @@ public class VoiceChatPlugin extends Bot.Listener {
|
|||
initializationData = new InitializationData(bot.options().host(), secretPacket);
|
||||
|
||||
try {
|
||||
address = InetAddress.getByName(bot.options().host());
|
||||
final InetAddress address = InetAddress.getByName(bot.options().host());
|
||||
socketAddress = new InetSocketAddress(address, initializationData.serverPort());
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -115,7 +114,7 @@ public class VoiceChatPlugin extends Bot.Listener {
|
|||
}
|
||||
}
|
||||
|
||||
private class VoiceChatSocketBase {
|
||||
private static class VoiceChatSocketBase {
|
||||
private final byte[] BUFFER = new byte[4096];
|
||||
|
||||
public RawUdpPacket read (DatagramSocket socket) {
|
||||
|
@ -146,7 +145,7 @@ public class VoiceChatPlugin extends Bot.Listener {
|
|||
running = false;
|
||||
}
|
||||
|
||||
private class ClientVoiceChatSocket extends VoiceChatSocketBase {
|
||||
private static class ClientVoiceChatSocket extends VoiceChatSocketBase {
|
||||
private DatagramSocket socket;
|
||||
|
||||
public void open() throws SocketException {
|
||||
|
@ -173,9 +172,5 @@ public class VoiceChatPlugin extends Bot.Listener {
|
|||
socket = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return socket == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class Instrument {
|
|||
return new Instrument(-1, null, 0, sound);
|
||||
}
|
||||
|
||||
private static Instrument[] values = {HARP, BASEDRUM, SNARE, HAT, BASS, FLUTE, BELL, GUITAR, CHIME, XYLOPHONE, IRON_XYLOPHONE, COW_BELL, DIDGERIDOO, BIT, BANJO, PLING};
|
||||
private static final Instrument[] values = {HARP, BASEDRUM, SNARE, HAT, BASS, FLUTE, BELL, GUITAR, CHIME, XYLOPHONE, IRON_XYLOPHONE, COW_BELL, DIDGERIDOO, BIT, BANJO, PLING};
|
||||
public static Instrument fromId (int id) {
|
||||
return values[id];
|
||||
}
|
||||
|
|
|
@ -16,16 +16,6 @@ public class MidiConverter {
|
|||
public static final int NOTE_ON = 0x90;
|
||||
public static final int NOTE_OFF = 0x80;
|
||||
|
||||
// public static Song getSongFromUrl(URL url) throws IOException, InvalidMidiDataException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException {
|
||||
// Sequence sequence = MidiSystem.getSequence(DownloadUtilities.DownloadToInputStream(url, 5*1024*1024));
|
||||
// return getSong(sequence, Paths.get(url.toURI().getPath()).getFileName().toString());
|
||||
// }
|
||||
//
|
||||
// public static Song getSongFromFile(File file) throws InvalidMidiDataException, IOException {
|
||||
// Sequence sequence = MidiSystem.getSequence(file);
|
||||
// return getSong(sequence, file.getName());
|
||||
// }
|
||||
|
||||
public static Song getSongFromBytes(byte[] bytes, String name, Bot bot) throws InvalidMidiDataException, IOException {
|
||||
Sequence sequence = MidiSystem.getSequence(new ByteArrayInputStream(bytes));
|
||||
return getSong(sequence, name, bot);
|
||||
|
|
|
@ -14,18 +14,6 @@ public class Note implements Comparable<Note> {
|
|||
|
||||
@Override
|
||||
public int compareTo(Note other) {
|
||||
if (time < other.time) {
|
||||
return -1;
|
||||
}
|
||||
else if (time > other.time) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int noteId () {
|
||||
return pitch + instrument.id * 25;
|
||||
return Long.compare(time, other.time);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,4 @@ public class SongLoaderException extends Exception {
|
|||
super();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public SongLoaderException (Component message, Throwable cause) {
|
||||
super(null, cause);
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,8 +94,4 @@ public class SongLoaderRunnable implements Runnable {
|
|||
private void showFailedMessage () {
|
||||
bot.chat().tellraw(Component.translatable("Failed to load song: %s", exception.message()).color(NamedTextColor.RED));
|
||||
}
|
||||
|
||||
private File getSongFile (String name) {
|
||||
return new File(MusicPlayerPlugin.SONG_DIR, name);
|
||||
}
|
||||
}
|
|
@ -25,13 +25,6 @@ public class AES {
|
|||
return buffer.array();
|
||||
}
|
||||
|
||||
public static UUID getUUIDFromBytes(byte[] bytes) {
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
|
||||
long most = byteBuffer.getLong();
|
||||
long least = byteBuffer.getLong();
|
||||
return new UUID(most, least);
|
||||
}
|
||||
|
||||
private static byte[] generateIV() {
|
||||
byte[] iv = new byte[16];
|
||||
RANDOM.nextBytes(iv);
|
||||
|
|
|
@ -55,8 +55,4 @@ public class DownloadUtilities {
|
|||
}
|
||||
// Closing a ByteArrayInputStream has no effect, so I do not close it.
|
||||
}
|
||||
|
||||
public static InputStream DownloadToInputStream(URL url, int maxSize) throws KeyManagementException, NoSuchAlgorithmException, IOException {
|
||||
return new ByteArrayInputStream(DownloadToByteArray(url, maxSize));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,14 +29,9 @@ public class FriendlyByteBuf extends ByteBuf {
|
|||
this(Unpooled.buffer());
|
||||
}
|
||||
|
||||
public ByteBuf getUnderlyingByteBuf() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
public FriendlyByteBuf writeByteArray(byte[] bs) {
|
||||
public void writeByteArray(byte[] bs) {
|
||||
writeVarInt(bs.length);
|
||||
writeBytes(bs);
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] readByteArray() {
|
||||
|
@ -70,24 +65,22 @@ public class FriendlyByteBuf extends ByteBuf {
|
|||
return i;
|
||||
}
|
||||
|
||||
public FriendlyByteBuf writeUUID(UUID uUID) {
|
||||
public void writeUUID(UUID uUID) {
|
||||
writeLong(uUID.getMostSignificantBits());
|
||||
writeLong(uUID.getLeastSignificantBits());
|
||||
return this;
|
||||
}
|
||||
|
||||
public UUID readUUID() {
|
||||
return new UUID(readLong(), readLong());
|
||||
}
|
||||
|
||||
public FriendlyByteBuf writeVarInt(int i) {
|
||||
public void writeVarInt(int i) {
|
||||
while ((i & -128) != 0) {
|
||||
writeByte(i & 127 | 128);
|
||||
i >>>= 7;
|
||||
}
|
||||
|
||||
writeByte(i);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String readUtf(int i) {
|
||||
|
@ -107,14 +100,13 @@ public class FriendlyByteBuf extends ByteBuf {
|
|||
}
|
||||
}
|
||||
|
||||
public FriendlyByteBuf writeUtf(String string, int i) {
|
||||
public void writeUtf(String string, int i) {
|
||||
byte[] bs = string.getBytes(StandardCharsets.UTF_8);
|
||||
if (bs.length > i) {
|
||||
throw new EncoderException("String too big (was " + bs.length + " bytes encoded, max " + i + ')');
|
||||
} else {
|
||||
writeVarInt(bs.length);
|
||||
writeBytes(bs);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,8 +114,8 @@ public class FriendlyByteBuf extends ByteBuf {
|
|||
return readUtf(32767);
|
||||
}
|
||||
|
||||
public FriendlyByteBuf writeUtf(String string) {
|
||||
return writeUtf(string, 32767);
|
||||
public void writeUtf(String string) {
|
||||
writeUtf(string, 32767);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,7 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.util;
|
|||
// Original code made by _ChipMC_ IIRC and I ported it to Java
|
||||
public class IllegalCharactersUtilities {
|
||||
public static boolean isAllowedCharacter (char character) {
|
||||
return character != '\u00a7' && character != '\u007f';
|
||||
return character != '§' && character != '\u007f';
|
||||
}
|
||||
|
||||
public static boolean containsIllegalCharacters (String string) {
|
||||
|
|
|
@ -106,11 +106,6 @@ public class LoggerUtilities {
|
|||
out.close();
|
||||
}
|
||||
|
||||
public static synchronized BufferedReader getLogReader(File file) throws IOException {
|
||||
GZIPInputStream in = new GZIPInputStream(new FileInputStream(file));
|
||||
return new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static synchronized String getLogDate(File file) throws IOException {
|
||||
InputStreamReader isr = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
|
||||
BufferedReader reader = new BufferedReader(isr);
|
||||
|
|
|
@ -30,15 +30,4 @@ public class InitializationData {
|
|||
this.groupsEnabled = secretPacket.groupsEnabled();
|
||||
this.allowRecording = secretPacket.allowRecording();
|
||||
}
|
||||
|
||||
private static class HostData {
|
||||
private final String ip;
|
||||
private final int port;
|
||||
|
||||
public HostData(String ip, int port) {
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,11 +26,6 @@ public class NetworkMessage {
|
|||
@Getter private Packet<? extends Packet<?>> packet;
|
||||
@Getter private SocketAddress address;
|
||||
|
||||
public NetworkMessage(long timestamp, Packet<?> packet) {
|
||||
this(timestamp);
|
||||
this.packet = packet;
|
||||
}
|
||||
|
||||
public NetworkMessage(Packet<?> packet) {
|
||||
this(System.currentTimeMillis());
|
||||
this.packet = packet;
|
||||
|
|
Loading…
Reference in a new issue