actually use less dependencies/.,,.,.
This commit is contained in:
@@ -10,9 +10,9 @@ import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import land.chipmunk.chayapak.chomens_bot.plugins.*;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.RandomStringUtilities;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -125,7 +125,7 @@ public class Bot {
|
||||
|
||||
final String _username = options.username();
|
||||
|
||||
if (_username == null) username = RandomStringUtils.randomAlphanumeric(8);
|
||||
if (_username == null) username = RandomStringUtilities.generate(8);
|
||||
else username = _username;
|
||||
|
||||
Session session = new TcpClientSession(host, port, new MinecraftProtocol(username), null);
|
||||
|
||||
@@ -18,7 +18,7 @@ public class CowsayCommand implements Command {
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("<cow> <{message}>");
|
||||
usages.add("<{message}>");
|
||||
|
||||
return usages;
|
||||
}
|
||||
@@ -35,11 +35,9 @@ public class CowsayCommand implements Command {
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
final String cow = args[0];
|
||||
final String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
|
||||
final String message = String.join(" ", args);
|
||||
|
||||
final CowExecutor cowExecutor = new CowExecutor();
|
||||
cowExecutor.setCowfile(cow);
|
||||
cowExecutor.setMessage(message);
|
||||
|
||||
final String result = cowExecutor.execute();
|
||||
|
||||
@@ -4,13 +4,13 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.commands.*;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ExceptionUtilities;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -146,7 +146,7 @@ public class CommandHandlerPlugin {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
final String stackTrace = ExceptionUtils.getStackTrace(e);
|
||||
final String stackTrace = ExceptionUtilities.getStacktrace(e);
|
||||
if (inGame) {
|
||||
if (bot.options().useChat() || !bot.options().useCore()) return Component.text(e.toString()).color(NamedTextColor.RED);
|
||||
return Component
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package land.chipmunk.chayapak.chomens_bot.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class ExceptionUtilities {
|
||||
// totallynotskidded™ from apache's common utils thingy
|
||||
public static String getStacktrace (Throwable throwable) {
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw, true);
|
||||
|
||||
throwable.printStackTrace(pw);
|
||||
|
||||
return sw.getBuffer().toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package land.chipmunk.chayapak.chomens_bot.util;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
// https://stackoverflow.com/questions/41107/how-to-generate-a-random-alpha-numeric-string
|
||||
// but modified
|
||||
public class RandomStringUtilities {
|
||||
private static String nextString() {
|
||||
// fard
|
||||
for (int i = 0; i < buf.length; i++)
|
||||
buf[i] = symbols[random.nextInt(symbols.length)];
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
private static final String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
private static final String lower = upper.toLowerCase();
|
||||
|
||||
private static final String digits = "0123456789";
|
||||
|
||||
private static final String alphanum = upper + lower + digits;
|
||||
|
||||
private static final char[] symbols = alphanum.toCharArray();
|
||||
|
||||
private static char[] buf = null;
|
||||
|
||||
private static final SecureRandom random = new SecureRandom();
|
||||
|
||||
// TODO: mabe support stuff than alpha-numeric
|
||||
public static String generate (int length) {
|
||||
buf = new char[length];
|
||||
|
||||
return nextString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user