mirror of
https://github.com/hhhzzzsss/HBot-Release.git
synced 2024-11-14 10:55:00 -05:00
1.18
This commit is contained in:
parent
112185bfb7
commit
96587e8acc
77 changed files with 1170 additions and 792 deletions
|
@ -1,3 +0,0 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.github.hhhzzzsss.hbot.Main
|
||||
|
|
@ -1,34 +1,33 @@
|
|||
package com.github.hhhzzzsss.hbot;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.listeners.DisconnectListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.TickListener;
|
||||
import com.github.hhhzzzsss.hbot.modules.ChatQueue;
|
||||
import com.github.hhhzzzsss.hbot.modules.PositionManager;
|
||||
import com.github.hhhzzzsss.hbot.modules.StateManager;
|
||||
import com.github.hhhzzzsss.hbot.util.HashUtils;
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
import com.github.steveice10.packetlib.ProxyInfo;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import io.netty.util.concurrent.FastThreadLocal;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.listeners.*;
|
||||
import com.github.hhhzzzsss.hbot.modules.*;
|
||||
import com.github.hhhzzzsss.hbot.util.HashUtils;
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.packetlib.ProxyInfo;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import io.netty.util.concurrent.FastThreadLocal;
|
||||
import lombok.*;
|
||||
|
||||
public abstract class Bot {
|
||||
public static final ArrayList<Bot> BOTLIST = new ArrayList<>();
|
||||
|
||||
|
@ -77,8 +76,8 @@ public abstract class Bot {
|
|||
session = new TcpClientSession(host, port, protocol, PROXY);
|
||||
session.addListener(new SessionAdapter() {
|
||||
@Override
|
||||
public synchronized void packetReceived(PacketReceivedEvent event) {
|
||||
packetQueue.add(event.getPacket());
|
||||
public synchronized void packetReceived(Session session, Packet packet) {
|
||||
packetQueue.add(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -181,7 +180,7 @@ public abstract class Bot {
|
|||
|
||||
public List<PacketFuture> packetFutures = new LinkedList<>();
|
||||
private void processPacket(Packet packet) {
|
||||
if (packet instanceof ServerJoinGamePacket) {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
loggedIn = true;
|
||||
}
|
||||
|
||||
|
@ -287,7 +286,7 @@ public abstract class Bot {
|
|||
}
|
||||
|
||||
public void sendChatInstantly(String chat) {
|
||||
sendPacket(new ClientChatPacket(chat));
|
||||
sendPacket(new ServerboundChatPacket(chat));
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
|
|
@ -17,13 +17,14 @@ public class Config {
|
|||
static final File file = new File("config.yml");
|
||||
@Getter static Config config;
|
||||
|
||||
@Data
|
||||
@Getter
|
||||
public static class BotInfo {
|
||||
String host;
|
||||
int port;
|
||||
String serverNick;
|
||||
String discordToken;
|
||||
String categoryName;
|
||||
public String host;
|
||||
public int port;
|
||||
public String serverNick;
|
||||
public String discordToken;
|
||||
public String categoryName;
|
||||
public boolean isDefault;
|
||||
}
|
||||
|
||||
ArrayList<BotInfo> bots;
|
||||
|
|
|
@ -7,7 +7,7 @@ public class Main {
|
|||
|
||||
public static void main(String[] args) {
|
||||
for (Config.BotInfo botInfo : Config.getConfig().getBots()) {
|
||||
HBot hbot = new HBot(botInfo.getHost(), botInfo.getPort(), botInfo.getServerNick(), botInfo.getDiscordToken(), botInfo.getCategoryName());
|
||||
HBot hbot = new HBot(botInfo);
|
||||
hbots.add(hbot);
|
||||
}
|
||||
for (HBot hbot : hbots) {
|
||||
|
|
|
@ -1,37 +1,45 @@
|
|||
package com.github.hhhzzzsss.hbot.block;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.ChunkSection;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.tcp.io.ByteBufNetInput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import lombok.*;
|
||||
import java.io.IOException;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ChunkColumn {
|
||||
@Getter private final ChunkPos pos;
|
||||
@Getter private Chunk[] data = new Chunk[16];
|
||||
|
||||
public void loadColumn(Column column) {
|
||||
Chunk[] chunks = column.getChunks();
|
||||
for (int i=0; i<16; i++) {
|
||||
if (chunks[i] != null) {
|
||||
data[i] = chunks[i];
|
||||
}
|
||||
@Getter private ChunkSection[] chunks;
|
||||
private int minY;
|
||||
|
||||
public ChunkColumn(ChunkPos chunkPos, byte[] data, int worldHeight, int minY) throws IOException {
|
||||
this.pos = chunkPos;
|
||||
this.minY = minY;
|
||||
ByteBuf byteBuf = Unpooled.wrappedBuffer(data);
|
||||
NetInput in = new ByteBufNetInput(byteBuf);
|
||||
int numSections = -Math.floorDiv(-worldHeight, 16);
|
||||
chunks = new ChunkSection[numSections];
|
||||
for (int i=0; i<numSections; i++) {
|
||||
chunks[i] = ChunkSection.read(in, 15);
|
||||
}
|
||||
}
|
||||
|
||||
public int getBlock(int x, int y, int z) {
|
||||
int yIdx = y>>4;
|
||||
if (data[yIdx] == null) return 0;
|
||||
return data[yIdx].get(x, y&15, z);
|
||||
int yIdx = (y-minY)>>4;
|
||||
if (chunks[yIdx] == null) return 0;
|
||||
return chunks[yIdx].getBlock(x, y&15, z);
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, int z, int id) {
|
||||
int yIdx = y>>4;
|
||||
if (data[yIdx] == null) {
|
||||
data[yIdx] = new Chunk();
|
||||
data[yIdx].set(0, 0, 0, 0);
|
||||
int yIdx = (y-minY)>>4;
|
||||
if (chunks[yIdx] == null) {
|
||||
chunks[yIdx] = new ChunkSection();
|
||||
chunks[yIdx].setBlock(0, 0, 0, 0);
|
||||
}
|
||||
data[yIdx].set(x, y&15, z, id);
|
||||
chunks[yIdx].setBlock(x, y&15, z, id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.github.hhhzzzsss.hbot.block;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.DataPalette;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.*;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
@Setter(AccessLevel.NONE)
|
||||
@AllArgsConstructor
|
||||
public class UnusedChunk {
|
||||
private static final int GLOBAL_BLOCK_PALETTE_BITS_PER_ENTRY = 15;
|
||||
private static final int GLOBAL_BIOME_PALETTE_BITS_PER_ENTRY = 6;
|
||||
|
||||
private static final int AIR = 0;
|
||||
|
||||
private int blockCount;
|
||||
private @NonNull DataPalette chunkData;
|
||||
private @NonNull DataPalette biomeData;
|
||||
|
||||
public UnusedChunk() {
|
||||
this(0, DataPalette.createForChunk(GLOBAL_BLOCK_PALETTE_BITS_PER_ENTRY), DataPalette.createForBiome(GLOBAL_BIOME_PALETTE_BITS_PER_ENTRY));
|
||||
}
|
||||
|
||||
public static UnusedChunk read(NetInput in) throws IOException {
|
||||
|
||||
int blockCount = in.readShort();
|
||||
|
||||
DataPalette chunkPalette = DataPalette.read(in, PaletteType.CHUNK, GLOBAL_BLOCK_PALETTE_BITS_PER_ENTRY);
|
||||
DataPalette biomePalette = DataPalette.read(in, PaletteType.BIOME, GLOBAL_BIOME_PALETTE_BITS_PER_ENTRY);
|
||||
return new UnusedChunk(blockCount, chunkPalette, biomePalette);
|
||||
}
|
||||
}
|
|
@ -1,61 +1,81 @@
|
|||
package com.github.hhhzzzsss.hbot.block;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.listeners.DisconnectListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.hhhzzzsss.hbot.util.BlockUtils;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUnloadChunkPacket;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.BlockChangeEntry;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundRespawnPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundBlockUpdatePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundForgetLevelChunkPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLevelChunkWithLightPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundSectionBlocksUpdatePacket;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.IntTagConverter;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class World implements PacketListener, DisconnectListener {
|
||||
|
||||
|
||||
public HashMap<ChunkPos, ChunkColumn> chunks = new HashMap<>();
|
||||
@Getter private int height = 256;
|
||||
@Getter private int minY = 0;
|
||||
|
||||
@Override
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerChunkDataPacket) {
|
||||
ServerChunkDataPacket t_packet = (ServerChunkDataPacket) packet;
|
||||
Column column = t_packet.getColumn();
|
||||
ChunkPos pos = new ChunkPos(column.getX(), column.getZ());
|
||||
|
||||
if (!chunks.containsKey(pos) || column.getBiomeData() != null) {
|
||||
ChunkColumn chunk = new ChunkColumn(pos);
|
||||
chunk.loadColumn(column);
|
||||
chunks.put(pos, chunk);
|
||||
}
|
||||
else {
|
||||
ChunkColumn chunk = chunks.get(pos);
|
||||
chunk.loadColumn(column);
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
ClientboundLoginPacket t_packet = (ClientboundLoginPacket) packet;
|
||||
CompoundTag dimensionEntry = t_packet.getDimension();
|
||||
height = ((IntTag)dimensionEntry.get("height")).getValue();
|
||||
minY = ((IntTag)dimensionEntry.get("min_y")).getValue();
|
||||
} else if (packet instanceof ClientboundRespawnPacket) {
|
||||
ClientboundRespawnPacket t_packet = (ClientboundRespawnPacket) packet;
|
||||
CompoundTag dimensionEntry = t_packet.getDimension();
|
||||
height = ((IntTag)dimensionEntry.get("height")).getValue();
|
||||
minY = ((IntTag)dimensionEntry.get("min_y")).getValue();
|
||||
chunks.clear();
|
||||
} if (packet instanceof ClientboundLevelChunkWithLightPacket) {
|
||||
ClientboundLevelChunkWithLightPacket t_packet = (ClientboundLevelChunkWithLightPacket) packet;
|
||||
ChunkPos pos = new ChunkPos(t_packet.getX(), t_packet.getZ());
|
||||
ChunkColumn column;
|
||||
try {
|
||||
column = new ChunkColumn(pos, t_packet.getChunkData(), height, minY);
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
}
|
||||
chunks.put(pos, column);
|
||||
// if (!chunks.containsKey(pos) || column.getBiomeData() != null) {
|
||||
// ChunkColumn chunk = new ChunkColumn(pos);
|
||||
// chunk.loadColumn(column);
|
||||
// chunks.put(pos, chunk);
|
||||
// }
|
||||
// else {
|
||||
// ChunkColumn chunk = chunks.get(pos);
|
||||
// chunk.loadColumn(column);
|
||||
// }
|
||||
}
|
||||
else if (packet instanceof ServerBlockChangePacket) {
|
||||
ServerBlockChangePacket t_packet = (ServerBlockChangePacket) packet;
|
||||
Position pos = t_packet.getRecord().getPosition();
|
||||
int id = t_packet.getRecord().getBlock();
|
||||
else if (packet instanceof ClientboundBlockUpdatePacket) {
|
||||
ClientboundBlockUpdatePacket t_packet = (ClientboundBlockUpdatePacket) packet;
|
||||
Position pos = t_packet.getEntry().getPosition();
|
||||
int id = t_packet.getEntry().getBlock();
|
||||
setBlock(pos.getX(), pos.getY(), pos.getZ(), id);
|
||||
}
|
||||
else if (packet instanceof ServerMultiBlockChangePacket) {
|
||||
ServerMultiBlockChangePacket t_packet = (ServerMultiBlockChangePacket) packet;
|
||||
for (BlockChangeRecord bcr : t_packet.getRecords()) {
|
||||
else if (packet instanceof ClientboundSectionBlocksUpdatePacket) {
|
||||
ClientboundSectionBlocksUpdatePacket t_packet = (ClientboundSectionBlocksUpdatePacket) packet;
|
||||
for (BlockChangeEntry bcr : t_packet.getEntries()) {
|
||||
Position pos = bcr.getPosition();
|
||||
int id = bcr.getBlock();
|
||||
setBlock(pos.getX(), pos.getY(), pos.getZ(), id);
|
||||
}
|
||||
}
|
||||
else if (packet instanceof ServerUnloadChunkPacket) {
|
||||
ServerUnloadChunkPacket t_packet = (ServerUnloadChunkPacket) packet;
|
||||
else if (packet instanceof ClientboundForgetLevelChunkPacket) {
|
||||
ClientboundForgetLevelChunkPacket t_packet = (ClientboundForgetLevelChunkPacket) packet;
|
||||
chunks.remove(new ChunkPos(t_packet.getX(), t_packet.getZ()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package com.github.hhhzzzsss.hbot.command;
|
||||
|
||||
public interface ChatCommand extends Command {
|
||||
public void executeChat(String sender, String args) throws CommandException;
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.github.hhhzzzsss.hbot.command;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class ChatSender {
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
private final String displayName;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.github.hhhzzzsss.hbot.command;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public interface GlobalDiscordCommand extends DiscordCommand {
|
||||
}
|
|
@ -9,16 +9,17 @@ import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
|||
import com.github.hhhzzzsss.hbot.listeners.TickListener;
|
||||
import com.github.hhhzzzsss.hbot.util.BlockUtils;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.BitStorage;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.ChunkSection;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.Palette;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.CommandBlockMode;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientUpdateCommandBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.CommandBlockMode;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
|
@ -37,6 +38,7 @@ public class CommandCore implements TickListener, PacketListener {
|
|||
@Getter private CoreProcess process = null;
|
||||
|
||||
private int coreCheckCooldown = 20;
|
||||
boolean retry = false;
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
|
@ -59,9 +61,11 @@ public class CommandCore implements TickListener, PacketListener {
|
|||
corePos = relocatePos;
|
||||
relocatePos = null;
|
||||
}
|
||||
retry = false;
|
||||
}
|
||||
else {
|
||||
fillCore(trackedPos);
|
||||
fillCore(trackedPos, retry);
|
||||
retry = true;
|
||||
coreCheckCooldown = 30; // delay 30 ticks if it's filling the core
|
||||
}
|
||||
}
|
||||
|
@ -86,11 +90,11 @@ public class CommandCore implements TickListener, PacketListener {
|
|||
|
||||
@Getter @Setter private int commandLag = 0;
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerJoinGamePacket) {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
bot.sendCommand("/gamerule commandBlockOutput false");
|
||||
}
|
||||
else if (packet instanceof ServerChatPacket) {
|
||||
ServerChatPacket t_packet = (ServerChatPacket) packet;
|
||||
else if (packet instanceof ClientboundChatPacket) {
|
||||
ClientboundChatPacket t_packet = (ClientboundChatPacket) packet;
|
||||
if (t_packet.getMessage() instanceof TranslatableComponent) {
|
||||
TranslatableComponent message = (TranslatableComponent) t_packet.getMessage();
|
||||
if (message.key().equals("advMode.setCommand.success") || message.key().equals("advMode.notEnabled") || message.key().equals("advMode.notAllowed")) {
|
||||
|
@ -137,10 +141,10 @@ public class CommandCore implements TickListener, PacketListener {
|
|||
private boolean checkCore(ChunkPos pos) {
|
||||
ChunkColumn chunkColumn = world.getChunk(pos);
|
||||
if (chunkColumn == null) return false;
|
||||
Chunk section = chunkColumn.getData()[0];
|
||||
ChunkSection section = chunkColumn.getChunks()[0];
|
||||
if (section == null) return false;
|
||||
BitStorage storage = section.getStorage();
|
||||
Palette palette = section.getPalette();
|
||||
BitStorage storage = section.getChunkData().getStorage();
|
||||
Palette palette = section.getChunkData().getPalette();
|
||||
for (int i=0; i<256*targetCoreHeight; i++) {
|
||||
if (!isCommandBlock(palette.idToState(storage.get(i)))) {
|
||||
return false;
|
||||
|
@ -157,16 +161,16 @@ public class CommandCore implements TickListener, PacketListener {
|
|||
return checkCore(corePos);
|
||||
}
|
||||
|
||||
private void fillCore(ChunkPos pos) {
|
||||
private void fillCore(ChunkPos pos, boolean retry) {
|
||||
int x = pos.getX() << 4;
|
||||
int z = pos.getZ() << 4;
|
||||
bot.sendCommand(String.format("/fill %d %d %d %d %d %d repeating_command_block replace", x, 0, z, x+15, targetCoreHeight-1, z+15));
|
||||
bot.sendCommand(String.format("/fill %d %d %d %d %d %d repeating_command_block %s", x, world.getMinY(), z, x+15, world.getMinY()+targetCoreHeight-1, z+15, retry ? "destroy" : "replace"));
|
||||
}
|
||||
|
||||
private void deleteCore() {
|
||||
int x = corePos.getX() << 4;
|
||||
int z = corePos.getZ() << 4;
|
||||
run(String.format("/fill %d 0 %d %d 15 %d air replace repeating_command_block", x, z, x+15, z+15));
|
||||
run(String.format("/fill %d %d %d %d %d %d air replace repeating_command_block", x, world.getMinY(), z, x+15, world.getMinY()+15, z+15));
|
||||
idx = 0;
|
||||
}
|
||||
|
||||
|
@ -203,7 +207,7 @@ public class CommandCore implements TickListener, PacketListener {
|
|||
int z = (corePos.getZ() << 4) + ((idx>>4) & 15);
|
||||
int y = idx >> 8;
|
||||
Position p = new Position(x, y, z);
|
||||
bot.sendPacket(new ClientUpdateCommandBlockPacket(p, command, CommandBlockMode.AUTO, false, false, true));
|
||||
bot.sendPacket(new ServerboundSetCommandBlockPacket(p, command, CommandBlockMode.AUTO, false, false, true));
|
||||
idx = (idx+1) % (256*coreHeight);
|
||||
commandLag++;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.processes.BadApple;
|
||||
import com.github.hhhzzzsss.hbot.processes.PCrashProcess;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -38,7 +33,7 @@ public class BadAppleCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.modules.BlacklistManager;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class BlacklistCommand implements ChatCommand, DiscordCommand {
|
||||
private final HBot hbot;
|
||||
|
@ -41,7 +39,7 @@ public class BlacklistCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
execute(parser, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
@ -56,11 +54,25 @@ public class BlacklistCommand implements ChatCommand, DiscordCommand {
|
|||
String subCommand = parser.readWord(true);
|
||||
if (subCommand.equalsIgnoreCase("add")) {
|
||||
String username = parser.readString(true).replaceAll("(?<!\\\\)%", "§").replace("\\%", "%");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(username);
|
||||
username = hbot.getPlayerListTracker().getRecordedLoginName(uuid);
|
||||
if (username == null) {
|
||||
throw new CommandException("UUID was not found in cache");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {}
|
||||
hbot.getBlacklistManager().add(username);
|
||||
platform.sendMessage("&7Added &3" + username + " &7to the blacklist");
|
||||
}
|
||||
else if (subCommand.equalsIgnoreCase("remove")) {
|
||||
String username = parser.readString(true).replaceAll("(?<!\\\\)%", "§").replace("\\%", "%");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(username);
|
||||
username = hbot.getPlayerListTracker().getRecordedLoginName(uuid);
|
||||
if (username == null) {
|
||||
throw new CommandException("UUID was not found in cache");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {}
|
||||
hbot.getBlacklistManager().remove(username);
|
||||
platform.sendMessage("&7Removed &3" + username + " &7from the blacklist");
|
||||
}
|
||||
|
|
|
@ -1,16 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.processes.SchemProcess;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.processes.boxstructure.BoxStructure;
|
||||
|
||||
import lombok.*;
|
||||
|
@ -43,7 +34,7 @@ public class BoxStructureCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
execute(parser, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -34,7 +31,7 @@ public class CBCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
String command = parser.readString(true);
|
||||
if (!command.toLowerCase().matches("/?(essentials:|extras:)?(e?sudo|e?nick(name)?|rank|prefix|tag) .?b?.?l?hbot .*")) {
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.modules.CommandLooper;
|
||||
import com.github.hhhzzzsss.hbot.util.ChatUtils;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -42,7 +37,7 @@ public class CLoopCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot, hbot.getCommandCore()));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -40,7 +36,7 @@ public class CoreCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -34,7 +31,7 @@ public class CreatorCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +1,10 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.block.BlockSelector;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.processes.SchemProcess;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.processes.dla.BrownianProcess;
|
||||
import com.github.hhhzzzsss.hbot.processes.dla.DLAProcess;
|
||||
import com.github.hhhzzzsss.hbot.processes.dla.SkyFallProcess;
|
||||
import com.github.hhhzzzsss.hbot.processes.mapart.MapartLoaderThread;
|
||||
import com.github.hhhzzzsss.hbot.processes.mapart.MapartProcess;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -51,7 +37,7 @@ public class DLACommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
execute(parser, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.util.BlockUtils;
|
||||
|
||||
import lombok.*;
|
||||
|
@ -38,13 +34,13 @@ public class DebugCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot, hbot.getCommandCore()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeDiscord(MessageReceivedEvent event, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getDiscord(hbot, event, "Command Loop"));
|
||||
execute(args, PlatformInfo.getDiscord(hbot, event, "Debug"));
|
||||
}
|
||||
|
||||
private void execute(String args, PlatformInfo platform) throws CommandException {
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -34,7 +31,7 @@ public class DiscordMessageCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.discord.DiscordUtils;
|
||||
|
||||
import lombok.*;
|
||||
|
@ -35,7 +32,7 @@ public class EchoCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
bot.sendChat(parser.readString(true));
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.processes.EntitySpammer;
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -35,7 +31,7 @@ public class EntitySpammerCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,7 @@ import java.util.Comparator;
|
|||
import java.util.List;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.Command;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandList;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.Permission;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.commandcore.CommandCore;
|
||||
import com.github.hhhzzzsss.hbot.discord.DiscordManager;
|
||||
import com.github.hhhzzzsss.hbot.modules.ChatCommandHandler;
|
||||
|
@ -21,7 +16,7 @@ import net.dv8tion.jda.api.EmbedBuilder;
|
|||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class HelpCommand implements ChatCommand, DiscordCommand {
|
||||
public class HelpCommand implements ChatCommand, GlobalDiscordCommand {
|
||||
public final Bot bot;
|
||||
public final CommandList commandList;
|
||||
public final ChatCommandHandler commandHandler;
|
||||
|
@ -65,7 +60,7 @@ public class HelpCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
String prefix = commandHandler.getPrefix();
|
||||
if (args.length() == 0) { // List commands
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
|
@ -3,11 +3,7 @@ package com.github.hhhzzzsss.hbot.commands;
|
|||
import java.util.UUID;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -38,7 +34,7 @@ public class KickCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.entity.PlayerData;
|
||||
|
||||
import lombok.*;
|
||||
|
@ -36,7 +32,7 @@ public class ListCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(PlatformInfo.getMinecraft(hbot, hbot.getCommandCore()));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class LockCommand implements ChatCommand, DiscordCommand {
|
||||
private final HBot hbot;
|
||||
|
@ -35,11 +33,11 @@ public class LockCommand implements ChatCommand, DiscordCommand {
|
|||
|
||||
@Override
|
||||
public int getPermission() {
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
execute(parser, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
@ -54,11 +52,25 @@ public class LockCommand implements ChatCommand, DiscordCommand {
|
|||
String subCommand = parser.readWord(true);
|
||||
if (subCommand.equalsIgnoreCase("add")) {
|
||||
String username = parser.readString(true).replaceAll("(?<!\\\\)%", "§").replace("\\%", "%");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(username);
|
||||
username = hbot.getPlayerListTracker().getRecordedLoginName(uuid);
|
||||
if (username == null) {
|
||||
throw new CommandException("UUID was not found in cache");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {}
|
||||
hbot.getLockManager().add(username);
|
||||
platform.sendMessage("&7Added &3" + username + " &7to the lock list");
|
||||
}
|
||||
else if (subCommand.equalsIgnoreCase("remove")) {
|
||||
String username = parser.readString(true).replaceAll("(?<!\\\\)%", "§").replace("\\%", "%");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(username);
|
||||
username = hbot.getPlayerListTracker().getRecordedLoginName(uuid);
|
||||
if (username == null) {
|
||||
throw new CommandException("UUID was not found in cache");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {}
|
||||
hbot.getLockManager().remove(username);
|
||||
platform.sendMessage("&7Removed &3" + username + " &7from the lock list");
|
||||
}
|
||||
|
|
|
@ -9,23 +9,16 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.Logger;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.discord.DiscordUtils;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
|
@ -62,7 +55,7 @@ public class LogQueryCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot, hbot.getCommandCore()));
|
||||
}
|
||||
|
||||
|
@ -236,7 +229,7 @@ public class LogQueryCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
}
|
||||
// Check if there's a '[x' on the left side
|
||||
if (idx != line.length()-2 && idx > 0 && line.charAt(idx) == 'x' && line.charAt(idx-1) == '[') {
|
||||
if (idx < line.length()-2 && idx > 0 && line.charAt(idx) == 'x' && line.charAt(idx-1) == '[') {
|
||||
repetitions = Integer.parseInt(line.substring(idx+1, line.length()-1));
|
||||
line = line.substring(0, idx-1);
|
||||
}
|
||||
|
|
|
@ -3,11 +3,7 @@ package com.github.hhhzzzsss.hbot.commands;
|
|||
import java.util.UUID;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -37,7 +33,7 @@ public class LoginNameCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
PlatformInfo platform = PlatformInfo.getMinecraft(hbot);
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
String player = parser.readString(false);
|
||||
|
@ -46,9 +42,13 @@ public class LoginNameCommand implements ChatCommand, DiscordCommand {
|
|||
uuid = UUID.fromString(player);
|
||||
}
|
||||
catch(IllegalArgumentException|NullPointerException e) {
|
||||
if (player == null) player = sender;
|
||||
player = player.replaceAll("(?<!\\\\)%", "§").replace("\\%", "%");
|
||||
uuid = hbot.getPlayerListTracker().getRecordedUUID(player);
|
||||
if (player == null) {
|
||||
player = sender.getDisplayName();
|
||||
uuid = sender.getUuid();
|
||||
} else {
|
||||
player = player.replaceAll("(?<!\\\\)%", "§").replace("\\%", "%");
|
||||
uuid = hbot.getPlayerListTracker().getRecordedUUID(player);
|
||||
}
|
||||
}
|
||||
String loginName = uuid == null ? null : hbot.getPlayerListTracker().getRecordedLoginName(uuid);
|
||||
if (loginName == null) {
|
||||
|
|
|
@ -1,19 +1,9 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.processes.SchemProcess;
|
||||
import com.github.hhhzzzsss.hbot.processes.mapart.MapartLoaderThread;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.processes.mapart.MapartProcess;
|
||||
|
||||
import lombok.*;
|
||||
|
@ -46,7 +36,7 @@ public class MapartCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
execute(parser, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
|
|
@ -6,21 +6,16 @@ import java.util.List;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.requests.RestAction;
|
||||
import net.dv8tion.jda.api.requests.restaction.MessageAction;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MassKickCommand implements DiscordCommand {
|
||||
public class MassKickCommand implements GlobalDiscordCommand {
|
||||
private final Bot bot;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,7 +37,7 @@ public class MsgFilterCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
execute(parser, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class MsgFilterCommand implements ChatCommand, DiscordCommand {
|
|||
@Override
|
||||
public void executeDiscord(MessageReceivedEvent event, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
execute(parser, PlatformInfo.getDiscord(hbot, event, "Player Filter"));
|
||||
execute(parser, PlatformInfo.getDiscord(hbot, event, "Message Filter"));
|
||||
}
|
||||
|
||||
private void execute(ArgsParser parser, PlatformInfo platform) throws CommandException {
|
||||
|
|
|
@ -4,11 +4,7 @@ import java.io.File;
|
|||
import java.util.Queue;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.modules.music.MusicPlayer;
|
||||
import com.github.hhhzzzsss.hbot.modules.music.Song;
|
||||
import com.github.hhhzzzsss.hbot.modules.music.SongLoaderThread;
|
||||
|
@ -48,7 +44,7 @@ public class MusicCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot, hbot.getCommandCore()));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.discord.MuteManager;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MuteCommand implements GlobalDiscordCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "mute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSyntax() {
|
||||
return new String[] {
|
||||
"list",
|
||||
"<discord tag>",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Mutes discord members";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPermission() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeDiscord(MessageReceivedEvent event, String args) throws CommandException {
|
||||
PlatformInfo platform = PlatformInfo.getDiscord(null, event, "Mute");
|
||||
if (args.length() == 0 || args.equalsIgnoreCase("list")) {
|
||||
MuteManager.readMuteList();
|
||||
if (MuteManager.getMutelist().size() == 0) {
|
||||
platform.sendDiscordOnlyMessage("There are currently no muted members");
|
||||
}
|
||||
else {
|
||||
platform.sendDiscordOnlyMessage("Muted members - `" + String.join("` | `", MuteManager.getMutelist()) + "`");
|
||||
}
|
||||
} else {
|
||||
Member member;
|
||||
List<Member> mentions = event.getMessage().getMentionedMembers();
|
||||
if (mentions.size() == 0) {
|
||||
try {
|
||||
member = event.getGuild().getMemberByTag(args);
|
||||
} catch (Exception e) {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
if (member == null) throw new CommandException("Member " + args + " could not be found");
|
||||
} else if (mentions.size() == 1) {
|
||||
member = mentions.get(0);
|
||||
} else {
|
||||
throw new CommandException("You can only mute one member at a time");
|
||||
}
|
||||
MuteManager.mute(member);
|
||||
platform.sendDiscordOnlyMessage("Muted " + member.getUser().getAsTag());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,9 +4,8 @@ import java.util.UUID;
|
|||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatSender;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.entity.PlayerData;
|
||||
import com.github.hhhzzzsss.hbot.subBots.OrbitBot;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
|
@ -36,12 +35,12 @@ public class OrbitCommand implements ChatCommand {
|
|||
|
||||
@Getter @Setter private int maxBots = 3;
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
UUID uuid = hbot.getPlayerListTracker().getRecordedUUID(sender);
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
UUID uuid = hbot.getPlayerListTracker().getRecordedUUID(sender.getName());
|
||||
if (uuid == null || !hbot.getPlayerListTracker().getPlayerList().containsKey(uuid)) {
|
||||
throw new CommandException("Could not find player " + sender);
|
||||
throw new CommandException("Could not find player " + sender.getName());
|
||||
}
|
||||
hbot.getOrbitManager().createOrbit(hbot, sender, uuid);
|
||||
hbot.sendChat("&7Creating a bot orbiting &3" + sender);
|
||||
hbot.getOrbitManager().createOrbit(hbot, sender.getName(), uuid);
|
||||
hbot.sendChat("&7Creating a bot orbiting &3" + sender.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.processes.PCrashProcess;
|
||||
import com.github.hhhzzzsss.hbot.util.HashUtils;
|
||||
|
||||
|
@ -41,7 +37,7 @@ public class PCrashCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
@ -64,7 +60,7 @@ public class PCrashCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
else if (subCommand.equalsIgnoreCase("player")) {
|
||||
String username = parser.readString(true).replaceAll("(?<!\\\\)%", "§").replace("\\%", "%");
|
||||
hbot.getCommandCore().run(String.format("/execute as %s at @s run particle dust 0 0 0 9 ~ ~1.5 ~ 0.1 0.1 0.1 0 2147483646 force @s", HashUtils.getOfflineUUID(username)));
|
||||
hbot.getCommandCore().run(String.format("/execute as %s at @s run particle minecraft:dust_color_transition 1 0 0 2 0 1 0 ~ ~1.5 ~ 0.1 0.1 0.1 0 2147483646 force @s", HashUtils.getOfflineUUID(username)));
|
||||
platform.sendMessage(String.format("&7Attempting to crash &3%s", username));
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.entity.EntitySelector;
|
||||
import com.github.hhhzzzsss.hbot.processes.ParticleCannon;
|
||||
import lombok.*;
|
||||
|
@ -36,7 +32,7 @@ public class ParticleCannonCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,7 @@ import java.util.regex.Pattern;
|
|||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -42,7 +38,7 @@ public class PlayerFilterCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
execute(parser, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@ package com.github.hhhzzzsss.hbot.commands;
|
|||
import java.awt.Color;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -36,7 +33,7 @@ public class RainbowifyCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,13 @@ package com.github.hhhzzzsss.hbot.commands;
|
|||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.Main;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class RestartCommand implements ChatCommand, DiscordCommand {
|
||||
public class RestartCommand implements ChatCommand, GlobalDiscordCommand {
|
||||
private final Bot bot;
|
||||
|
||||
@Override
|
||||
|
@ -34,7 +32,7 @@ public class RestartCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
bot.sendChatInstantly("Restarting...");
|
||||
new Thread(() -> {
|
||||
Main.restart();
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.UUID;
|
|||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatSender;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import lombok.*;
|
||||
|
||||
|
@ -32,14 +33,10 @@ public class RtpCommand implements ChatCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
UUID uuid = hbot.getPlayerListTracker().getRecordedUUID(sender);
|
||||
if (uuid == null) {
|
||||
throw new CommandException("Could not find player " + sender);
|
||||
}
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
int x = (int)((Math.random()*2.-1.) * 1000000);
|
||||
int z = (int)((Math.random()*2.-1.) * 1000000);
|
||||
hbot.getCommandCore().run(String.format("tp %s %d 100 %d", uuid.toString(), x, z));
|
||||
hbot.sendCommand(String.format("&7Teleporting &3%s &7to &3%d 100 %d", sender, x, z));
|
||||
hbot.getCommandCore().run(String.format("tp %s %d 100 %d", sender.getUuid().toString(), x, z));
|
||||
hbot.sendCommand(String.format("&7Teleporting &3%s &7to &3%d 100 %d", sender.getName(), x, z));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.processes.SchemProcess;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.processes.schem.SchemProcess;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -28,6 +23,7 @@ public class SchemCommand implements ChatCommand, DiscordCommand {
|
|||
public String[] getSyntax() {
|
||||
return new String[] {
|
||||
"list",
|
||||
"stop",
|
||||
"build [flags] <x> <y> <z> <filename>",
|
||||
"build -hcentered ... - horizontally centered",
|
||||
"build -vcentered ... - vertically centered",
|
||||
|
@ -43,11 +39,11 @@ public class SchemCommand implements ChatCommand, DiscordCommand {
|
|||
|
||||
@Override
|
||||
public int getPermission() {
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
execute(parser, PlatformInfo.getMinecraft(hbot, hbot.getCommandCore()));
|
||||
}
|
||||
|
@ -61,7 +57,7 @@ public class SchemCommand implements ChatCommand, DiscordCommand {
|
|||
private void execute(ArgsParser parser, PlatformInfo platform) throws CommandException {
|
||||
String subCommand = parser.readWord(true);
|
||||
|
||||
if (subCommand.equals("list")) {
|
||||
if (subCommand.equalsIgnoreCase("list")) {
|
||||
int color = 0;
|
||||
StringBuilder sb = new StringBuilder("&7Schematics -");
|
||||
for (File schemFile : SchemProcess.SCHEM_DIR.listFiles()) {
|
||||
|
@ -74,14 +70,23 @@ public class SchemCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
platform.sendMessage(sb.toString());
|
||||
}
|
||||
if (subCommand.equals("build")) {
|
||||
else if (subCommand.equalsIgnoreCase("stop")) {
|
||||
if (hbot.getCommandCore().getProcess() instanceof SchemProcess) {
|
||||
hbot.getCommandCore().getProcess().stop();
|
||||
platform.sendMessage("&7Schematic build canceled");
|
||||
}
|
||||
else {
|
||||
platform.sendMessage("&7No schematic is being built");
|
||||
}
|
||||
}
|
||||
else if (subCommand.equalsIgnoreCase("build")) {
|
||||
List<String> flags = parser.readFlags();
|
||||
int x = parser.readInt(true);
|
||||
int y = parser.readInt(true);
|
||||
int z = parser.readInt(true);
|
||||
String filename = parser.readString(true);
|
||||
hbot.getCommandCore().setProcess(new SchemProcess(hbot, x, y, z, filename, flags));
|
||||
platform.sendMessage("&7Now building &3" + filename);
|
||||
hbot.getCommandCore().setProcess(new SchemProcess(hbot, platform, x, y, z, filename, flags));
|
||||
platform.sendMessage("&7Loading &3" + filename + "&7...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.entity.EntitySelector;
|
||||
import com.github.hhhzzzsss.hbot.processes.Sentry;
|
||||
import com.github.hhhzzzsss.hbot.processes.Sentry.AttackType;
|
||||
|
@ -24,8 +20,9 @@ public class SentryCommand implements ChatCommand, DiscordCommand {
|
|||
@Override
|
||||
public String[] getSyntax() {
|
||||
return new String[] {
|
||||
"list - lists attack types",
|
||||
"list",
|
||||
"<entityType> <attackType> [maxTargets]",
|
||||
"stop"
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -40,7 +37,7 @@ public class SentryCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot, hbot.getCommandCore()));
|
||||
}
|
||||
|
||||
|
@ -62,6 +59,15 @@ public class SentryCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
platform.sendMessage(sb.toString());
|
||||
}
|
||||
else if (args.toLowerCase().startsWith("stop")) {
|
||||
if (hbot.getCommandCore().getProcess() instanceof Sentry) {
|
||||
hbot.getCommandCore().getProcess().stop();
|
||||
platform.sendMessage("&7Sentry stopped");
|
||||
}
|
||||
else {
|
||||
platform.sendMessage("&7Sentry is not currently running");
|
||||
}
|
||||
}
|
||||
else {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
EntitySelector entitySelector = parser.readEntitySelector(true);
|
||||
|
@ -70,7 +76,7 @@ public class SentryCommand implements ChatCommand, DiscordCommand {
|
|||
if (maxTargets == null) maxTargets = 3;
|
||||
if (hbot.getCommandCore().getProcess() == null || hbot.getCommandCore().getProcess() instanceof Sentry) {
|
||||
hbot.getCommandCore().forceSetProcess(new Sentry(hbot, entitySelector, type, maxTargets));
|
||||
hbot.sendChat("&7Enabled sentry");
|
||||
platform.sendMessage("&7Enabled sentry");
|
||||
}
|
||||
else {
|
||||
throw new CommandException("Another process is already running");
|
||||
|
|
|
@ -2,15 +2,13 @@ package com.github.hhhzzzsss.hbot.commands;
|
|||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.Main;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class StopCommand implements ChatCommand, DiscordCommand {
|
||||
public class StopCommand implements ChatCommand, GlobalDiscordCommand {
|
||||
private final Bot bot;
|
||||
|
||||
@Override
|
||||
|
@ -34,7 +32,7 @@ public class StopCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
bot.sendChatInstantly("Stopping...");
|
||||
new Thread(() -> {
|
||||
Main.stop();
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatSender;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.subBots.OrbitBot;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
|
@ -36,8 +33,8 @@ public class StopOrbitCommand implements ChatCommand {
|
|||
|
||||
@Getter @Setter private int maxBots = 3;
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
hbot.getOrbitManager().removeOrbit(sender);
|
||||
hbot.sendChat("&7Removing the bot orbiting &3" + sender);
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
hbot.getOrbitManager().removeOrbit(sender.getName());
|
||||
hbot.sendChat("&7Removing the bot orbiting &3" + sender.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,7 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.entity.PlayerData;
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -43,7 +40,7 @@ public class SuperCBCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
String command = parser.readString(true);
|
||||
execute(command);
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -35,7 +31,7 @@ public class ToggleVisibilityCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,7 @@ package com.github.hhhzzzsss.hbot.commands;
|
|||
import java.util.List;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.processes.treegen.TreeGenProcess;
|
||||
import com.github.hhhzzzsss.hbot.processes.treegen.TreeType;
|
||||
|
||||
|
@ -49,7 +45,7 @@ public class TreeGenCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
execute(args, PlatformInfo.getMinecraft(hbot));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,7 @@ package com.github.hhhzzzsss.hbot.commands;
|
|||
import java.util.UUID;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.ArgsParser;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -37,12 +33,15 @@ public class UUIDCommand implements ChatCommand, DiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
PlatformInfo platform = PlatformInfo.getMinecraft(hbot);
|
||||
ArgsParser parser = new ArgsParser(this, args);
|
||||
String username = parser.readString(false);
|
||||
if (username == null) username = sender;
|
||||
else username = username.replaceAll("(?<!\\\\)%", "§").replace("\\%", "%");
|
||||
if (username == null) {
|
||||
platform.sendMessage("&7Your UUID is &3" + sender.getUuid().toString());
|
||||
return;
|
||||
}
|
||||
username = username.replaceAll("(?<!\\\\)%", "§").replace("\\%", "%");
|
||||
UUID uuid = hbot.getPlayerListTracker().getRecordedUUID(username);
|
||||
if (uuid == null) {
|
||||
throw new CommandException("Could not get uuid of " + username.replace("§", "&"));
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package com.github.hhhzzzsss.hbot.commands;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.GlobalDiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.discord.MuteManager;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class UnmuteCommand implements GlobalDiscordCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "unmute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSyntax() {
|
||||
return new String[] {
|
||||
"list",
|
||||
"<discord tag>",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Unmutes discord members";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPermission() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeDiscord(MessageReceivedEvent event, String args) throws CommandException {
|
||||
PlatformInfo platform = PlatformInfo.getDiscord(null, event, "Mute");
|
||||
if (args.length() == 0 || args.equalsIgnoreCase("list")) {
|
||||
MuteManager.readMuteList();
|
||||
if (MuteManager.getMutelist().size() == 0) {
|
||||
platform.sendDiscordOnlyMessage("There are currently no muted members");
|
||||
}
|
||||
else {
|
||||
platform.sendDiscordOnlyMessage("Muted members - `" + String.join("` | `", MuteManager.getMutelist()) + "`");
|
||||
}
|
||||
} else {
|
||||
Member member;
|
||||
List<Member> mentions = event.getMessage().getMentionedMembers();
|
||||
if (mentions.size() == 0) {
|
||||
try {
|
||||
member = event.getGuild().getMemberByTag(args);
|
||||
} catch (Exception e) {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
if (member == null) throw new CommandException("Member " + args + " could not be found");
|
||||
} else if (mentions.size() == 1) {
|
||||
member = mentions.get(0);
|
||||
} else {
|
||||
throw new CommandException("You can only mute one member at a time");
|
||||
}
|
||||
MuteManager.unmute(member);
|
||||
platform.sendDiscordOnlyMessage("Unmuted " + member.getUser().getAsTag());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.github.hhhzzzsss.hbot.commands;
|
|||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatSender;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
|
||||
import lombok.*;
|
||||
|
@ -31,7 +32,7 @@ public class ValidateCommand implements ChatCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void executeChat(String sender, String args) throws CommandException {
|
||||
public void executeChat(ChatSender sender, String args) throws CommandException {
|
||||
bot.sendChat("&aValid Hash");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,7 @@ package com.github.hhhzzzsss.hbot.discord;
|
|||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.Logger;
|
||||
import com.github.hhhzzzsss.hbot.command.Command;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.DiscordCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.Permission;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.util.ChatUtils;
|
||||
|
||||
import lombok.*;
|
||||
|
@ -13,8 +10,11 @@ import net.dv8tion.jda.api.entities.Member;
|
|||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.*;
|
||||
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class DiscordEventListener extends ListenerAdapter {
|
||||
|
@ -33,16 +33,38 @@ public class DiscordEventListener extends ListenerAdapter {
|
|||
public static final String bridgeMessageFormat = "/tellraw @a [{\"text\":\"\"},{\"text\":\"§8[§9HBot Discord§8] \",\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[{\"text\":\"§9Click to join the Discord\"}]},\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://discord.gg/5wv6xQEj9X\"}},{\"text\":\"§3%s \",\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[{\"text\":\"§b%s\\n§7%s\\n\\n§9Click to copy Discord tag\"}]},\"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"%s\"}},{\"text\":\"§8› §7%s\"}]";
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
if (event.getAuthor().isBot() || !event.getMessage().getCategory().getName().equalsIgnoreCase(hbot.getCategoryName())) {
|
||||
if (event.getAuthor().isBot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Message msg = event.getMessage();
|
||||
String raw = msg.getContentDisplay();
|
||||
|
||||
if (hbot.isDefault()) {
|
||||
MuteManager.checkMember(event.getMember());
|
||||
}
|
||||
|
||||
Message message = event.getMessage();
|
||||
|
||||
boolean hasNoCategory = true;
|
||||
for (String category : HBot.getCategoryList()) {
|
||||
if (message.getCategory().getName().equalsIgnoreCase(category)) {
|
||||
hasNoCategory = false;
|
||||
}
|
||||
}
|
||||
boolean inOwnCategory = message.getCategory().getName().equalsIgnoreCase(hbot.getCategoryName());
|
||||
|
||||
if (!inOwnCategory) {
|
||||
if (!hbot.isDefault()) {
|
||||
return;
|
||||
}
|
||||
else if (!hasNoCategory) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String raw = message.getContentDisplay();
|
||||
User user = event.getAuthor();
|
||||
Member member = event.getMember();
|
||||
|
||||
if (event.getChannel().getName().equalsIgnoreCase("hbot-logs") && !raw.startsWith(discordManager.getPrefix())) {
|
||||
if (event.getChannel().getName().equalsIgnoreCase("hbot-logs") && inOwnCategory && !raw.startsWith(discordManager.getPrefix())) {
|
||||
//hbot.sendCommand(String.format("/bcraw &8[&9HBot Discord&8] &3%s &8› &7%s", event.getMember().getEffectiveName(), raw));
|
||||
String nick = DiscordNickManager.getNick(member).replaceAll("&([0-9a-frlonmk])", "§$1");
|
||||
String tag = user.getAsTag();
|
||||
|
@ -57,28 +79,42 @@ public class DiscordEventListener extends ListenerAdapter {
|
|||
String command = split[0];
|
||||
String args = (split.length == 2 ? split[1] : "").trim();
|
||||
try {
|
||||
processCommand(event, command, args);
|
||||
processCommand(event, command, args, hasNoCategory);
|
||||
}
|
||||
catch (CommandException e) {
|
||||
msg.reply(DiscordUtils.sanitizeMentions(e.getMessage())).queue();
|
||||
message.reply(DiscordUtils.sanitizeMentions(e.getMessage())).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processCommand(MessageReceivedEvent event, String commandName, String args) throws CommandException {
|
||||
private void processCommand(MessageReceivedEvent event, String commandName, String args, boolean calledOutOfCateogory) throws CommandException {
|
||||
Command command = hbot.getCommandList().get(commandName.toLowerCase());
|
||||
if (command == null) {
|
||||
throw new CommandException("Unknown command: " + commandName);
|
||||
//throw new CommandException("Unknown command: " + commandName);
|
||||
return;
|
||||
}
|
||||
if (!(command instanceof DiscordCommand)) {
|
||||
throw new CommandException("This command cannot be run from Discord");
|
||||
}
|
||||
if (calledOutOfCateogory && !(command instanceof GlobalDiscordCommand)) {
|
||||
throw new CommandException(
|
||||
"This command can only be run inside a channel category corresponding to one of the servers ("
|
||||
+String.join(", ", HBot.getCategoryList())
|
||||
+")");
|
||||
}
|
||||
if (command.getPermission() > DiscordUtils.getMemberPermissionInt(event.getMember())) {
|
||||
throw new CommandException("You don't have permission to run this command");
|
||||
}
|
||||
|
||||
((DiscordCommand) command).executeDiscord(event, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
|
||||
if (hbot.isDefault()) {
|
||||
MuteManager.checkMember(event.getMember());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(DisconnectEvent event) {
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
package com.github.hhhzzzsss.hbot.discord;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.Permission;
|
||||
import com.github.hhhzzzsss.hbot.listeners.DisconnectListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import net.dv8tion.jda.api.entities.Category;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.utils.ChunkingFilter;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class DiscordManager implements PacketListener, DisconnectListener {
|
||||
|
@ -37,6 +37,8 @@ public class DiscordManager implements PacketListener, DisconnectListener {
|
|||
|
||||
public void login() {
|
||||
JDABuilder builder = JDABuilder.createDefault(hbot.getBotToken());
|
||||
builder.setChunkingFilter(ChunkingFilter.ALL);
|
||||
builder.setMemberCachePolicy(MemberCachePolicy.ALL);
|
||||
builder.enableIntents(GatewayIntent.GUILD_MEMBERS);
|
||||
builder.setActivity(Activity.playing("Loading..."));
|
||||
listener = new DiscordEventListener(this, hbot);
|
||||
|
@ -106,7 +108,7 @@ public class DiscordManager implements PacketListener, DisconnectListener {
|
|||
|
||||
@Override
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerJoinGamePacket) {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
setConnectedStatus(true);
|
||||
}
|
||||
}
|
||||
|
|
100
src/main/java/com/github/hhhzzzsss/hbot/discord/MuteManager.java
Normal file
100
src/main/java/com/github/hhhzzzsss/hbot/discord/MuteManager.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package com.github.hhhzzzsss.hbot.discord;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class MuteManager {
|
||||
|
||||
@Getter private static Set<String> mutelist = Collections.synchronizedSet(new TreeSet<>());
|
||||
|
||||
private static Gson gson = new Gson();
|
||||
@Getter private static final File mutelistFile = new File("mutelist.json");
|
||||
|
||||
static {
|
||||
readMuteList();
|
||||
}
|
||||
|
||||
public static void readMuteList() {
|
||||
if (mutelistFile.exists()) {
|
||||
InputStreamReader isReader;
|
||||
try {
|
||||
isReader = new InputStreamReader(new FileInputStream(mutelistFile), "UTF-8");
|
||||
|
||||
JsonReader jsonReader = new JsonReader(isReader);
|
||||
Type treeSetType = new TypeToken<TreeSet<String>>(){}.getType();
|
||||
synchronized (mutelist) {
|
||||
mutelist = gson.fromJson(jsonReader, treeSetType);
|
||||
}
|
||||
jsonReader.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeMuteList() {
|
||||
String json;
|
||||
synchronized(mutelist) {
|
||||
json = gson.toJson(mutelist);
|
||||
}
|
||||
try {
|
||||
FileWriter fileWriter;
|
||||
fileWriter = new FileWriter(mutelistFile);
|
||||
|
||||
BufferedWriter bufferWriter = new BufferedWriter(fileWriter);
|
||||
bufferWriter.write(json);
|
||||
bufferWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void mute(Member member) throws CommandException {
|
||||
mutelist.add(member.getUser().getAsTag());
|
||||
Guild guild = member.getGuild();
|
||||
List<Role> roles = guild.getRolesByName("muted", true);
|
||||
if (roles.size() == 0) throw new CommandException("Muted role does not seem to exist");
|
||||
guild.addRoleToMember(member, roles.get(0)).queue();
|
||||
}
|
||||
|
||||
public static void unmute(Member member) {
|
||||
mutelist.remove(member.getUser().getAsTag());
|
||||
for (Role role : member.getRoles()) {
|
||||
if (role.getName().equalsIgnoreCase("muted")) {
|
||||
member.getGuild().removeRoleFromMember(member, role).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkMember(Member member) {
|
||||
if (mutelist.contains(member.getUser().getAsTag())) {
|
||||
Guild guild = member.getGuild();
|
||||
List<Role> roles = guild.getRolesByName("muted", true);
|
||||
if (roles.size() > 0) {
|
||||
guild.addRoleToMember(member, roles.get(0)).queue();
|
||||
}
|
||||
} else {
|
||||
for (Role role : member.getRoles()) {
|
||||
if (role.getName().equalsIgnoreCase("muted")) {
|
||||
member.getGuild().removeRoleFromMember(member, role).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +1,13 @@
|
|||
package com.github.hhhzzzsss.hbot.entity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.util.EntityUtils;
|
||||
import com.github.hhhzzzsss.hbot.util.EntityUtils.EntityData;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.*;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddEntityPacket;
|
||||
import lombok.Getter;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class Entity implements Comparable<Entity> {
|
||||
|
@ -35,7 +28,7 @@ public class Entity implements Comparable<Entity> {
|
|||
|
||||
protected Entity() {}
|
||||
|
||||
public Entity(ServerSpawnEntityPacket p) {
|
||||
public Entity(ClientboundAddEntityPacket p) {
|
||||
eid = p.getEntityId();
|
||||
uuid = p.getUuid();
|
||||
type = p.getType();
|
||||
|
@ -49,14 +42,14 @@ public class Entity implements Comparable<Entity> {
|
|||
zVel = p.getMotionZ();
|
||||
}
|
||||
|
||||
public void update(ServerEntityPositionPacket p) {
|
||||
public void update(ClientboundMoveEntityPosPacket p) {
|
||||
x += p.getMoveX();
|
||||
y += p.getMoveY();
|
||||
z += p.getMoveZ();
|
||||
onGround = p.isOnGround();
|
||||
}
|
||||
|
||||
public void update(ServerEntityPositionRotationPacket p) {
|
||||
public void update(ClientboundMoveEntityPosRotPacket p) {
|
||||
x += p.getMoveX();
|
||||
y += p.getMoveY();
|
||||
z += p.getMoveZ();
|
||||
|
@ -65,15 +58,15 @@ public class Entity implements Comparable<Entity> {
|
|||
onGround = p.isOnGround();
|
||||
}
|
||||
|
||||
public void update(ServerEntityRotationPacket p) {
|
||||
public void update(ClientboundMoveEntityRotPacket p) {
|
||||
yaw = p.getYaw();
|
||||
pitch = p.getPitch();
|
||||
onGround = p.isOnGround();
|
||||
}
|
||||
|
||||
public void update(ServerEntityHeadLookPacket p) {}
|
||||
public void update(ClientboundRotateHeadPacket p) {}
|
||||
|
||||
public void update(ServerEntityTeleportPacket p) {
|
||||
public void update(ClientboundTeleportEntityPacket p) {
|
||||
x = p.getX();
|
||||
y = p.getY();
|
||||
z = p.getZ();
|
||||
|
@ -82,13 +75,13 @@ public class Entity implements Comparable<Entity> {
|
|||
onGround = p.isOnGround();
|
||||
}
|
||||
|
||||
public void update(ServerEntityVelocityPacket p) {
|
||||
public void update(ClientboundSetEntityMotionPacket p) {
|
||||
xVel = p.getMotionX();
|
||||
yVel = p.getMotionY();
|
||||
zVel = p.getMotionZ();
|
||||
}
|
||||
|
||||
public void update(ServerEntityStatusPacket p) {}
|
||||
public void update(ClientboundEntityEventPacket p) {}
|
||||
|
||||
@Override
|
||||
public int compareTo(Entity other) {
|
||||
|
|
|
@ -1,29 +1,22 @@
|
|||
package com.github.hhhzzzsss.hbot.entity;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.listeners.DisconnectListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.*;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddMobPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPlayerPacket;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.listeners.DisconnectListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerRemoveEntitiesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnLivingEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
public class EntityTracker implements PacketListener, DisconnectListener {
|
||||
@Getter private ConcurrentLinkedQueue<Packet> packetQueue = new ConcurrentLinkedQueue<>();
|
||||
@Getter private Map<Integer, Entity> entityMap = Collections.synchronizedMap(new HashMap<Integer, Entity>());
|
||||
|
@ -34,64 +27,64 @@ public class EntityTracker implements PacketListener, DisconnectListener {
|
|||
|
||||
@Override
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerSpawnEntityPacket) {
|
||||
if (packet instanceof ClientboundAddEntityPacket) {
|
||||
if (trackEntities) {
|
||||
ServerSpawnEntityPacket t_packet = (ServerSpawnEntityPacket) packet;
|
||||
ClientboundAddEntityPacket t_packet = (ClientboundAddEntityPacket) packet;
|
||||
Entity entity = new Entity(t_packet);
|
||||
addEntity(entity);
|
||||
}
|
||||
}
|
||||
else if (packet instanceof ServerSpawnLivingEntityPacket) {
|
||||
else if (packet instanceof ClientboundAddMobPacket) {
|
||||
if (trackLiving) {
|
||||
ServerSpawnLivingEntityPacket t_packet = (ServerSpawnLivingEntityPacket) packet;
|
||||
ClientboundAddMobPacket t_packet = (ClientboundAddMobPacket) packet;
|
||||
Entity entity = new LivingEntity(t_packet);
|
||||
addEntity(entity);
|
||||
}
|
||||
}
|
||||
else if (packet instanceof ServerSpawnPlayerPacket) {
|
||||
else if (packet instanceof ClientboundAddPlayerPacket) {
|
||||
if (trackPlayers) {
|
||||
ServerSpawnPlayerPacket t_packet = (ServerSpawnPlayerPacket) packet;
|
||||
ClientboundAddPlayerPacket t_packet = (ClientboundAddPlayerPacket) packet;
|
||||
Entity entity = new PlayerEntity(t_packet);
|
||||
addEntity(entity);
|
||||
}
|
||||
}
|
||||
else if (packet instanceof ServerEntityPositionPacket) {
|
||||
ServerEntityPositionPacket t_packet = (ServerEntityPositionPacket) packet;
|
||||
else if (packet instanceof ClientboundMoveEntityPosPacket) {
|
||||
ClientboundMoveEntityPosPacket t_packet = (ClientboundMoveEntityPosPacket) packet;
|
||||
Entity entity = entityMap.get(t_packet.getEntityId());
|
||||
if (entity != null) entity.update(t_packet);
|
||||
}
|
||||
else if (packet instanceof ServerEntityPositionRotationPacket) {
|
||||
ServerEntityPositionRotationPacket t_packet = (ServerEntityPositionRotationPacket) packet;
|
||||
else if (packet instanceof ClientboundMoveEntityPosRotPacket) {
|
||||
ClientboundMoveEntityPosRotPacket t_packet = (ClientboundMoveEntityPosRotPacket) packet;
|
||||
Entity entity = entityMap.get(t_packet.getEntityId());
|
||||
if (entity != null) entity.update(t_packet);
|
||||
}
|
||||
else if (packet instanceof ServerEntityRotationPacket) {
|
||||
ServerEntityRotationPacket t_packet = (ServerEntityRotationPacket) packet;
|
||||
else if (packet instanceof ClientboundMoveEntityRotPacket) {
|
||||
ClientboundMoveEntityRotPacket t_packet = (ClientboundMoveEntityRotPacket) packet;
|
||||
Entity entity = entityMap.get(t_packet.getEntityId());
|
||||
if (entity != null) entity.update(t_packet);
|
||||
}
|
||||
else if (packet instanceof ServerEntityHeadLookPacket) {
|
||||
ServerEntityHeadLookPacket t_packet = (ServerEntityHeadLookPacket) packet;
|
||||
else if (packet instanceof ClientboundRotateHeadPacket) {
|
||||
ClientboundRotateHeadPacket t_packet = (ClientboundRotateHeadPacket) packet;
|
||||
Entity entity = entityMap.get(t_packet.getEntityId());
|
||||
if (entity != null) entity.update(t_packet);
|
||||
}
|
||||
else if (packet instanceof ServerEntityTeleportPacket) {
|
||||
ServerEntityTeleportPacket t_packet = (ServerEntityTeleportPacket) packet;
|
||||
else if (packet instanceof ClientboundTeleportEntityPacket) {
|
||||
ClientboundTeleportEntityPacket t_packet = (ClientboundTeleportEntityPacket) packet;
|
||||
Entity entity = entityMap.get(t_packet.getEntityId());
|
||||
if (entity != null) entity.update(t_packet);
|
||||
}
|
||||
else if (packet instanceof ServerEntityVelocityPacket) {
|
||||
ServerEntityVelocityPacket t_packet = (ServerEntityVelocityPacket) packet;
|
||||
else if (packet instanceof ClientboundSetEntityMotionPacket) {
|
||||
ClientboundSetEntityMotionPacket t_packet = (ClientboundSetEntityMotionPacket) packet;
|
||||
Entity entity = entityMap.get(t_packet.getEntityId());
|
||||
if (entity != null) entity.update(t_packet);
|
||||
}
|
||||
else if (packet instanceof ServerEntityStatusPacket) {
|
||||
ServerEntityStatusPacket t_packet = (ServerEntityStatusPacket) packet;
|
||||
else if (packet instanceof ClientboundEntityEventPacket) {
|
||||
ClientboundEntityEventPacket t_packet = (ClientboundEntityEventPacket) packet;
|
||||
Entity entity = entityMap.get(t_packet.getEntityId());
|
||||
if (entity != null) entity.update(t_packet);
|
||||
}
|
||||
if (packet instanceof ServerRemoveEntitiesPacket) {
|
||||
ServerRemoveEntitiesPacket t_packet = (ServerRemoveEntitiesPacket) packet;
|
||||
if (packet instanceof ClientboundRemoveEntitiesPacket) {
|
||||
ClientboundRemoveEntitiesPacket t_packet = (ClientboundRemoveEntitiesPacket) packet;
|
||||
for (int eid : t_packet.getEntityIds()) {
|
||||
removeEntity(eid);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.github.hhhzzzsss.hbot.entity;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EntityStatus;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnLivingEntityPacket;
|
||||
import lombok.*;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EntityEvent;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundRotateHeadPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddMobPacket;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class LivingEntity extends Entity {
|
||||
|
@ -13,7 +13,7 @@ public class LivingEntity extends Entity {
|
|||
|
||||
protected LivingEntity() {}
|
||||
|
||||
public LivingEntity(ServerSpawnLivingEntityPacket p) {
|
||||
public LivingEntity(ClientboundAddMobPacket p) {
|
||||
type = p.getType();
|
||||
eid = p.getEntityId();
|
||||
uuid = p.getUuid();
|
||||
|
@ -28,12 +28,12 @@ public class LivingEntity extends Entity {
|
|||
zVel = p.getMotionZ();
|
||||
}
|
||||
|
||||
public void update(ServerEntityHeadLookPacket p) {
|
||||
public void update(ClientboundRotateHeadPacket p) {
|
||||
headYaw = p.getHeadYaw();
|
||||
}
|
||||
|
||||
public void update(ServerEntityStatusPacket p) {
|
||||
if (p.getStatus() == EntityStatus.LIVING_DEATH) {
|
||||
public void update(ClientboundEntityEventPacket p) {
|
||||
if (p.getStatus() == EntityEvent.LIVING_DEATH) {
|
||||
alive = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.github.hhhzzzsss.hbot.entity;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPlayerPacket;
|
||||
|
||||
public class PlayerEntity extends LivingEntity {
|
||||
public PlayerEntity(ServerSpawnPlayerPacket p) {
|
||||
public PlayerEntity(ClientboundAddPlayerPacket p) {
|
||||
type = EntityType.PLAYER;
|
||||
eid = p.getEntityId();
|
||||
uuid = p.getUuid();
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package com.github.hhhzzzsss.hbot.modules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.TickListener;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class Broadcaster implements PacketListener, TickListener {
|
||||
|
@ -22,7 +23,7 @@ public class Broadcaster implements PacketListener, TickListener {
|
|||
private ArrayList<String> broadcasts = new ArrayList<>();
|
||||
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerJoinGamePacket && loginMessage != null) {
|
||||
if (packet instanceof ClientboundLoginPacket && loginMessage != null) {
|
||||
bot.sendChat(loginMessage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,15 +6,11 @@ import java.util.regex.Pattern;
|
|||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.Config;
|
||||
import com.github.hhhzzzsss.hbot.command.ChatCommand;
|
||||
import com.github.hhhzzzsss.hbot.command.Command;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandList;
|
||||
import com.github.hhhzzzsss.hbot.command.Permission;
|
||||
import com.github.hhhzzzsss.hbot.command.*;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.hhhzzzsss.hbot.util.ChatUtils;
|
||||
import com.github.hhhzzzsss.hbot.util.HashUtils;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundChatPacket;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import lombok.*;
|
||||
|
@ -39,26 +35,27 @@ public class ChatCommandHandler implements PacketListener {
|
|||
}
|
||||
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerChatPacket) {
|
||||
ServerChatPacket t_packet = (ServerChatPacket) packet;
|
||||
if (packet instanceof ClientboundChatPacket) {
|
||||
ClientboundChatPacket t_packet = (ClientboundChatPacket) packet;
|
||||
Component message = t_packet.getMessage();
|
||||
String strMessage = ChatUtils.getFullText(message);
|
||||
UUID uuid = t_packet.getSenderUuid();
|
||||
|
||||
if (t_packet.getSenderUuid().equals(new UUID(0, 0)) || t_packet.getSenderUuid().equals(bot.getUuid())) {
|
||||
if (uuid.equals(new UUID(0, 0)) || uuid.equals(bot.getUuid())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Matcher m;
|
||||
String username;
|
||||
String displayUsername;
|
||||
String command;
|
||||
String args;
|
||||
if ((m = essentialsPattern.matcher(strMessage)).matches()) {
|
||||
username = m.group(1);
|
||||
displayUsername = m.group(1);
|
||||
command = m.group(2);
|
||||
args = m.group(3).trim();
|
||||
}
|
||||
else if ((m = vanillaPattern.matcher(strMessage)).matches()) {
|
||||
username = m.group(1);
|
||||
displayUsername = m.group(1);
|
||||
command = m.group(2);
|
||||
args = m.group(3).trim();
|
||||
}
|
||||
|
@ -66,13 +63,13 @@ public class ChatCommandHandler implements PacketListener {
|
|||
return;
|
||||
}
|
||||
|
||||
String recordedName = playerListTracker.getRecordedLoginName(t_packet.getSenderUuid());
|
||||
if (recordedName != null) {
|
||||
username = recordedName;
|
||||
String actualName = playerListTracker.getRecordedLoginName(uuid);
|
||||
if (actualName == null) {
|
||||
actualName = displayUsername;
|
||||
}
|
||||
|
||||
try {
|
||||
runCommand(username, command, args);
|
||||
runCommand(new ChatSender(uuid, actualName, displayUsername), command, args);
|
||||
}
|
||||
catch (CommandException e) {
|
||||
bot.sendChat("&c" + e.getMessage());
|
||||
|
@ -80,7 +77,7 @@ public class ChatCommandHandler implements PacketListener {
|
|||
}
|
||||
}
|
||||
|
||||
public void runCommand(String sender, String commandName, String args) throws CommandException {
|
||||
public void runCommand(ChatSender sender, String commandName, String args) throws CommandException {
|
||||
Command command = commandList.get(commandName.toLowerCase());
|
||||
if (command == null) {
|
||||
throw new CommandException("Unknown command: " + commandName);
|
||||
|
@ -93,19 +90,21 @@ public class ChatCommandHandler implements PacketListener {
|
|||
if (args.length() == 0) {
|
||||
throw new CommandException("This command requires a hash for verification");
|
||||
}
|
||||
String unformattedSender = sender.replaceAll("§[0-9a-fklmnor]", "");
|
||||
String unformattedSender = sender.getName().replaceAll("§[0-9a-fklmnor]", "");
|
||||
int splitIdx = args.lastIndexOf(" ");
|
||||
String hash = args.substring(splitIdx+1);
|
||||
args = args.substring(0, Math.max(splitIdx, 0));
|
||||
int permLevel = 0;
|
||||
String plainTextBase = prefix + commandName + (args.isEmpty() ? "" : " " + args) + ";" + unformattedSender;
|
||||
if (HashUtils.isValidHash(plainTextBase, hash, ownerKey)) {
|
||||
String argRaw = args.isEmpty() ? "" : " " + args;
|
||||
String nameBase = prefix + commandName + argRaw + ";" + unformattedSender;
|
||||
String uuidBase = prefix + commandName + argRaw + ";" + sender.getUuid().toString();
|
||||
if (HashUtils.isValidHash(nameBase, hash, ownerKey) || HashUtils.isValidHash(uuidBase, hash, ownerKey)) {
|
||||
permLevel = Permission.OWNER.asInt();
|
||||
}
|
||||
else if (HashUtils.isValidHash(plainTextBase, hash, adminKey)) {
|
||||
else if (HashUtils.isValidHash(nameBase, hash, adminKey) || HashUtils.isValidHash(uuidBase, hash, adminKey)) {
|
||||
permLevel = Permission.ADMIN.asInt();
|
||||
}
|
||||
else if (HashUtils.isValidHash(plainTextBase, hash, trustedKey)) {
|
||||
else if (HashUtils.isValidHash(nameBase, hash, trustedKey) || HashUtils.isValidHash(uuidBase, hash, trustedKey)) {
|
||||
permLevel = Permission.TRUSTED.asInt();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -5,12 +5,12 @@ import com.github.hhhzzzsss.hbot.Logger;
|
|||
import com.github.hhhzzzsss.hbot.listeners.DisconnectListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.hhhzzzsss.hbot.util.ChatUtils;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class ChatLogger implements PacketListener, DisconnectListener {
|
||||
private final HBot hbot;
|
||||
|
@ -23,11 +23,11 @@ public class ChatLogger implements PacketListener, DisconnectListener {
|
|||
|
||||
@Override
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerJoinGamePacket) {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
log(String.format("Successfully logged in to %s:%d", hbot.getHost(), hbot.getPort()));
|
||||
}
|
||||
else if (packet instanceof ServerChatPacket) {
|
||||
ServerChatPacket t_packet = (ServerChatPacket) packet;
|
||||
else if (packet instanceof ClientboundChatPacket) {
|
||||
ClientboundChatPacket t_packet = (ClientboundChatPacket) packet;
|
||||
String fullText = ChatUtils.getFullText(t_packet.getMessage());
|
||||
if (fullText.equals("") || fullText.startsWith("Command set: ") || fullText.matches("[\u2800-\u28FF\\s]+") || fullText.matches("[⬛\\s]{60,}")) {
|
||||
return;
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package com.github.hhhzzzsss.hbot.modules;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.listeners.TickListener;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.listeners.TickListener;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ChatQueue implements TickListener {
|
||||
|
||||
|
@ -32,12 +33,12 @@ public class ChatQueue implements TickListener {
|
|||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime >= nextChatTime) {
|
||||
if (commandQueue.size() > 0 && currentTime >= nextCommandTime) {
|
||||
bot.sendPacket(new ClientChatPacket(commandQueue.poll()));
|
||||
bot.sendPacket(new ServerboundChatPacket(commandQueue.poll()));
|
||||
nextChatTime = currentTime + chatDelay;
|
||||
nextCommandTime = currentTime + commandDelay;
|
||||
}
|
||||
else if (chatQueue.size() > 0) {
|
||||
bot.sendPacket(new ClientChatPacket(chatQueue.poll()));
|
||||
bot.sendPacket(new ServerboundChatPacket(chatQueue.poll()));
|
||||
nextChatTime = currentTime + chatDelay;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
package com.github.hhhzzzsss.hbot.modules;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.sound.midi.InvalidMidiDataException;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.hhhzzzsss.hbot.util.ChatUtils;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundChatPacket;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MiscChatReactionsHandler implements PacketListener {
|
||||
|
||||
|
@ -21,12 +17,12 @@ public class MiscChatReactionsHandler implements PacketListener {
|
|||
|
||||
@Override
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerChatPacket) {
|
||||
ServerChatPacket t_packet = (ServerChatPacket) packet;
|
||||
if (packet instanceof ClientboundChatPacket) {
|
||||
ClientboundChatPacket t_packet = (ClientboundChatPacket) packet;
|
||||
Component message = t_packet.getMessage();
|
||||
String strMessage = ChatUtils.getFullText(message);
|
||||
if (!t_packet.getSenderUuid().equals(new UUID(0, 0)) && !t_packet.getSenderUuid().equals(hbot.getUuid())) {
|
||||
if (strMessage.toLowerCase().matches(".*\\bamogus\\b.*")) {
|
||||
/*if (strMessage.toLowerCase().matches(".*\\bamogus\\b.*")) {
|
||||
if (hbot.getMusicPlayer().noActiveSong()) {
|
||||
try {
|
||||
hbot.getMusicPlayer().play("amogus");
|
||||
|
@ -34,7 +30,7 @@ public class MiscChatReactionsHandler implements PacketListener {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
package com.github.hhhzzzsss.hbot.modules;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.entity.PlayerData;
|
||||
import com.github.hhhzzzsss.hbot.listeners.DisconnectListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.hhhzzzsss.hbot.util.HashUtils;
|
||||
import com.github.steveice10.mc.protocol.data.game.PlayerListEntry;
|
||||
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPlayerListEntryPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerInfoPacket;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import lombok.Getter;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListTracker implements PacketListener, DisconnectListener {
|
||||
|
||||
|
@ -36,8 +35,8 @@ public class PlayerListTracker implements PacketListener, DisconnectListener {
|
|||
|
||||
@Override
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerPlayerListEntryPacket) {
|
||||
ServerPlayerListEntryPacket t_packet = (ServerPlayerListEntryPacket) packet;
|
||||
if (packet instanceof ClientboundPlayerInfoPacket) {
|
||||
ClientboundPlayerInfoPacket t_packet = (ClientboundPlayerInfoPacket) packet;
|
||||
for (PlayerListEntry entry : t_packet.getEntries()) {
|
||||
UUID uuid = entry.getProfile().getId();
|
||||
if (t_packet.getAction() == PlayerListEntryAction.ADD_PLAYER) {
|
||||
|
|
|
@ -5,13 +5,13 @@ import com.github.hhhzzzsss.hbot.listeners.DisconnectListener;
|
|||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.PositionElement;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosRotPacket;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class PositionManager implements PacketListener, DisconnectListener {
|
||||
|
@ -27,7 +27,7 @@ public class PositionManager implements PacketListener, DisconnectListener {
|
|||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
bot.sendPacket(new ClientPlayerPositionRotationPacket(true, x, y, z, yaw, pitch));
|
||||
bot.sendPacket(new ServerboundMovePlayerPosRotPacket(true, x, y, z, yaw, pitch));
|
||||
}
|
||||
|
||||
public void moveLook(double x, double y, double z, float yaw, float pitch) {
|
||||
|
@ -36,19 +36,19 @@ public class PositionManager implements PacketListener, DisconnectListener {
|
|||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
bot.sendPacket(new ClientPlayerPositionRotationPacket(true, x, y, z, this.yaw, this.pitch));
|
||||
bot.sendPacket(new ServerboundMovePlayerPosRotPacket(true, x, y, z, this.yaw, this.pitch));
|
||||
}
|
||||
|
||||
public void look(float yaw, float pitch) {
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
bot.sendPacket(new ClientPlayerPositionRotationPacket(true, x, y, z, this.yaw, this.pitch));
|
||||
bot.sendPacket(new ServerboundMovePlayerPosRotPacket(true, x, y, z, this.yaw, this.pitch));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerPlayerPositionRotationPacket) {
|
||||
ServerPlayerPositionRotationPacket t_packet = (ServerPlayerPositionRotationPacket) packet;
|
||||
if (packet instanceof ClientboundPlayerPositionPacket) {
|
||||
ClientboundPlayerPositionPacket t_packet = (ClientboundPlayerPositionPacket) packet;
|
||||
boolean[] relFlags = new boolean[5];
|
||||
for (PositionElement element : t_packet.getRelative()) {
|
||||
relFlags[MagicValues.value(Integer.class, element)] = true;
|
||||
|
@ -58,7 +58,7 @@ public class PositionManager implements PacketListener, DisconnectListener {
|
|||
z = relFlags[2] ? z+t_packet.getZ() : t_packet.getZ();
|
||||
yaw = relFlags[3] ? yaw+t_packet.getYaw() : t_packet.getYaw();
|
||||
pitch = relFlags[4] ? pitch+t_packet.getPitch() : t_packet.getPitch();
|
||||
bot.sendPacket(new ClientTeleportConfirmPacket(t_packet.getTeleportId()));
|
||||
bot.sendPacket(new ServerboundAcceptTeleportationPacket(t_packet.getTeleportId()));
|
||||
spawned = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,29 @@
|
|||
package com.github.hhhzzzsss.hbot.modules;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.listeners.DisconnectListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.PacketListener;
|
||||
import com.github.hhhzzzsss.hbot.listeners.TickListener;
|
||||
import com.github.hhhzzzsss.hbot.util.ChatUtils;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EntityStatus;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EntityEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.notify.ClientNotification;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEvent;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundRespawnPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundGameEventPacket;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
|
@ -68,8 +70,8 @@ public class StateManager implements PacketListener, TickListener, DisconnectLis
|
|||
|
||||
@Override
|
||||
public void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerChatPacket) {
|
||||
ServerChatPacket t_packet = (ServerChatPacket) packet;
|
||||
if (packet instanceof ClientboundChatPacket) {
|
||||
ClientboundChatPacket t_packet = (ClientboundChatPacket) packet;
|
||||
|
||||
Component message = t_packet.getMessage();
|
||||
String jsonMessage = gson().serialize(message);
|
||||
|
@ -141,31 +143,31 @@ public class StateManager implements PacketListener, TickListener, DisconnectLis
|
|||
wrongPrefix = false;
|
||||
}
|
||||
}
|
||||
else if (packet instanceof ServerNotifyClientPacket) {
|
||||
ServerNotifyClientPacket t_packet = (ServerNotifyClientPacket) packet;
|
||||
if (t_packet.getNotification() == ClientNotification.CHANGE_GAMEMODE) {
|
||||
else if (packet instanceof ClientboundGameEventPacket) {
|
||||
ClientboundGameEventPacket t_packet = (ClientboundGameEventPacket) packet;
|
||||
if (t_packet.getNotification() == GameEvent.CHANGE_GAMEMODE) {
|
||||
gamemode = (GameMode) t_packet.getValue();
|
||||
}
|
||||
}
|
||||
else if (packet instanceof ServerJoinGamePacket) {
|
||||
ServerJoinGamePacket t_packet = (ServerJoinGamePacket) packet;
|
||||
else if (packet instanceof ClientboundLoginPacket) {
|
||||
ClientboundLoginPacket t_packet = (ClientboundLoginPacket) packet;
|
||||
entityId = t_packet.getEntityId();
|
||||
gamemode = t_packet.getGameMode();
|
||||
dimension = ((StringTag)t_packet.getDimension().get("effects")).getValue();
|
||||
}
|
||||
else if (packet instanceof ServerEntityStatusPacket) {
|
||||
ServerEntityStatusPacket t_packet = (ServerEntityStatusPacket) packet;
|
||||
else if (packet instanceof ClientboundEntityEventPacket) {
|
||||
ClientboundEntityEventPacket t_packet = (ClientboundEntityEventPacket) packet;
|
||||
if (t_packet.getEntityId() == entityId) {
|
||||
if (t_packet.getStatus() == EntityStatus.PLAYER_OP_PERMISSION_LEVEL_0) {
|
||||
if (t_packet.getStatus() == EntityEvent.PLAYER_OP_PERMISSION_LEVEL_0) {
|
||||
opped = false;
|
||||
}
|
||||
else if (t_packet.getStatus() == EntityStatus.PLAYER_OP_PERMISSION_LEVEL_4) {
|
||||
else if (t_packet.getStatus() == EntityEvent.PLAYER_OP_PERMISSION_LEVEL_4) {
|
||||
opped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packet instanceof ServerRespawnPacket) {
|
||||
ServerRespawnPacket t_packet = (ServerRespawnPacket) packet;
|
||||
else if (packet instanceof ClientboundRespawnPacket) {
|
||||
ClientboundRespawnPacket t_packet = (ClientboundRespawnPacket) packet;
|
||||
gamemode = t_packet.getGamemode();
|
||||
dimension = ((StringTag)t_packet.getDimension().get("effects")).getValue();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.Queue;
|
|||
import javax.sound.midi.InvalidMidiDataException;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.listeners.TickListener;
|
||||
|
||||
|
@ -34,12 +35,15 @@ public class MusicPlayer implements TickListener {
|
|||
* @throws IOException
|
||||
* @throws InvalidMidiDataException
|
||||
*/
|
||||
public void play(String location, PlatformInfo platform) throws IOException, InvalidMidiDataException {
|
||||
public void play(String location, PlatformInfo platform) throws IOException, InvalidMidiDataException, CommandException {
|
||||
SongLoaderThread loaderThread = new SongLoaderThread(location);
|
||||
if (noActiveSong()) {
|
||||
loadSong(loaderThread);
|
||||
platform.sendDiscordOnlyMessage("Playing `" + location + "`");
|
||||
}
|
||||
else if (songQueue.size() >= 100) {
|
||||
throw new CommandException("Cannot exceed max queue length of 100");
|
||||
}
|
||||
else {
|
||||
platform.sendMessage("&6Added &3" + location + " &6to the song queue");
|
||||
songQueue.add(loaderThread);
|
||||
|
|
|
@ -22,7 +22,7 @@ public class SongLoaderThread extends Thread {
|
|||
|
||||
boolean isUrl = false;
|
||||
|
||||
public SongLoaderThread(String location) throws IOException, InvalidMidiDataException {
|
||||
public SongLoaderThread(String location) throws IOException {
|
||||
this.location = location;
|
||||
if (location.startsWith("http://") || location.startsWith("https://")) {
|
||||
isUrl = true;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package com.github.hhhzzzsss.hbot.processes;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.commandcore.CoreProcess;
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Varargs;
|
||||
import org.luaj.vm2.lib.DebugLib;
|
||||
import org.luaj.vm2.lib.jse.JsePlatform;
|
||||
|
||||
// Currently unused and unfinished
|
||||
public class LuaProcess extends CoreProcess {
|
||||
public static final int MAX_INSTRUCTIONS = 10000;
|
||||
LuaValue script;
|
||||
|
||||
public LuaProcess(String script) {
|
||||
Globals globals = JsePlatform.standardGlobals();
|
||||
TimeoutDebugLib debugLib = new TimeoutDebugLib();
|
||||
globals.load(debugLib);
|
||||
debugLib.setInstructionTimeout(MAX_INSTRUCTIONS * 5);
|
||||
this.script = globals.load(script);
|
||||
}
|
||||
|
||||
public class TimeoutDebugLib extends DebugLib {
|
||||
private int instructionTimeout = 0;
|
||||
|
||||
public void setInstructionTimeout(int timeout) {
|
||||
instructionTimeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInstruction(int pc, Varargs v, int top) {
|
||||
if (instructionTimeout == 0) {
|
||||
throw new ScriptTimeoutException();
|
||||
}
|
||||
super.onInstruction(pc, v, top);
|
||||
instructionTimeout--;
|
||||
}
|
||||
|
||||
public static class ScriptTimeoutException extends RuntimeException {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSequence() {
|
||||
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ public class PCrashProcess extends CoreProcess {
|
|||
|
||||
@Override
|
||||
public void onTick() {
|
||||
hbot.getCommandCore().run(String.format("particle minecraft:dust 1 0 0 9 %f %f %f 0 0 0 0 2147483646 force", x, y, z));
|
||||
hbot.getCommandCore().run(String.format("particle minecraft:dust_color_transition 1 0 0 2 0 1 0 %f %f %f 0.1 0.1 0.1 0 2147483646 force @a", x, y, z));
|
||||
//hbot.getCommandCore().run(String.format("particle minecraft:dust 1 0 0 9 %f %f %f 0 0 0 0 2147483646 force", x, y, z));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,215 +0,0 @@
|
|||
package com.github.hhhzzzsss.hbot.processes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.block.Section;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.commandcore.CommandCore;
|
||||
import com.github.hhhzzzsss.hbot.commandcore.CoreProcess;
|
||||
import com.github.hhhzzzsss.hbot.util.BlockUtils;
|
||||
import com.github.steveice10.opennbt.NBTIO;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
|
||||
public class SchemProcess extends CoreProcess {
|
||||
private HBot hbot;
|
||||
private CommandCore commandCore;
|
||||
Section section;
|
||||
Iterable<String> flags;
|
||||
|
||||
boolean loaded = false;
|
||||
|
||||
public static final File SCHEM_DIR = new File("schematics");
|
||||
static {
|
||||
if (!SCHEM_DIR.exists()) {
|
||||
SCHEM_DIR.mkdir();
|
||||
}
|
||||
}
|
||||
|
||||
public SchemProcess(HBot hbot, int x, int y, int z, String filename, Iterable<String> flags) throws CommandException {
|
||||
this.hbot = hbot;
|
||||
commandCore = hbot.getCommandCore();
|
||||
this.flags = flags;
|
||||
|
||||
File schemPath = new File(SCHEM_DIR, filename);
|
||||
|
||||
if (!schemPath.exists()) schemPath = new File(SCHEM_DIR, filename + ".schem");
|
||||
if (!schemPath.exists()) schemPath = new File(SCHEM_DIR, filename + ".schematic");
|
||||
if (!schemPath.exists()) schemPath = new File(SCHEM_DIR, filename + ".nbt");
|
||||
if (!schemPath.exists()) {
|
||||
throw new CommandException("Could not find file: " + filename);
|
||||
}
|
||||
try {
|
||||
loadSchematic(new FileInputStream(schemPath));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new CommandException("Could not find file: " + schemPath);
|
||||
}
|
||||
section.setOrigin(x, y, z);
|
||||
section.cubicOptimize(256);
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public void loadSchematic(InputStream in) throws CommandException {
|
||||
CompoundTag nbt;
|
||||
try {
|
||||
Tag tag = NBTIO.readTag(new GZIPInputStream(in));
|
||||
if(!(tag instanceof CompoundTag)) {
|
||||
throw new CommandException("Not a valid schematic");
|
||||
}
|
||||
nbt = (CompoundTag) tag;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new CommandException("Error parsing schematic");
|
||||
}
|
||||
|
||||
if (nbt.contains("BlockData")) {
|
||||
loadNewSchematic(nbt);
|
||||
}
|
||||
else if (nbt.contains("Blocks")) {
|
||||
getOldSchematic(nbt);
|
||||
}
|
||||
else if (nbt.contains("blocks")) {
|
||||
loadStructureSchematic(nbt);
|
||||
}
|
||||
else {
|
||||
throw new CommandException("Not a valid schematic");
|
||||
}
|
||||
}
|
||||
|
||||
private void loadNewSchematic(CompoundTag nbt) {
|
||||
ShortTag widthtag = nbt.get("Width");
|
||||
ShortTag heighttag = nbt.get("Height");
|
||||
ShortTag lengthtag = nbt.get("Length");
|
||||
int width = widthtag.getValue();
|
||||
int height = heighttag.getValue();
|
||||
int length = lengthtag.getValue();
|
||||
section = new Section(width, height, length, flags);
|
||||
|
||||
CompoundTag palette = nbt.get("Palette");
|
||||
ByteArrayTag blockdata = nbt.get("BlockData");
|
||||
|
||||
String[] paletteArr = new String[palette.size()];
|
||||
int bpb = 1;
|
||||
while (palette.size() >> bpb > 0) {bpb++;}
|
||||
for (Tag paletteEntry : palette) {
|
||||
IntTag intEntry = (IntTag) paletteEntry;
|
||||
paletteArr[intEntry.getValue()] = intEntry.getName();
|
||||
}
|
||||
section.setPaletteEntries(paletteArr);
|
||||
|
||||
int varInt = 0;
|
||||
int varIntLength = 0;
|
||||
int storageIdx = 0;
|
||||
for (int i = 0; i < blockdata.length(); i++) {
|
||||
varInt |= (int)(blockdata.getValue(i) & 127) << (varIntLength++ * 7);
|
||||
if ((blockdata.getValue(i) & 128) == 128) {
|
||||
continue;
|
||||
}
|
||||
|
||||
section.setId(storageIdx++, varInt);
|
||||
|
||||
varInt = 0;
|
||||
varIntLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void getOldSchematic(CompoundTag nbt) {
|
||||
ShortTag widthtag = nbt.get("Width");
|
||||
ShortTag heighttag = nbt.get("Height");
|
||||
ShortTag lengthtag = nbt.get("Length");
|
||||
int width = widthtag.getValue();
|
||||
int height = heighttag.getValue();
|
||||
int length = lengthtag.getValue();
|
||||
section = new Section(width, height, length, flags);
|
||||
|
||||
ByteArrayTag blocks = nbt.get("Blocks");
|
||||
ByteArrayTag data = nbt.get("Data");
|
||||
|
||||
section.setPaletteEntries(BlockUtils.getLegacyIds());
|
||||
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
int legacyId = ((blocks.getValue(i) & 0xff) << 4) + (data.getValue(i) & 0xf);
|
||||
section.setId(i, legacyId);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadStructureSchematic(CompoundTag nbt) {
|
||||
ListTag sizetag = nbt.get("size");
|
||||
IntTag widthtag = sizetag.get(0);
|
||||
IntTag heighttag = sizetag.get(1);
|
||||
IntTag lengthtag = sizetag.get(2);
|
||||
int width = widthtag.getValue();
|
||||
int height = heighttag.getValue();
|
||||
int length = lengthtag.getValue();
|
||||
section = new Section(width, height, length, flags);
|
||||
|
||||
ListTag palette = nbt.get("palette");
|
||||
ListTag blocks = nbt.get("blocks");
|
||||
|
||||
String[] paletteArr = new String[palette.size()+1];
|
||||
int bpb = 1;
|
||||
while (paletteArr.length >> bpb > 0) {bpb++;}
|
||||
paletteArr[0] = "minecraft:air";
|
||||
for (int i=0; i<palette.size(); i++) {
|
||||
CompoundTag paletteEntry = palette.get(i);
|
||||
StringTag nametag = paletteEntry.get("Name");
|
||||
String s = nametag.getValue();
|
||||
if (paletteEntry.contains("Properties")) {
|
||||
CompoundTag propertiestag = paletteEntry.get("Properties");
|
||||
s += "[";
|
||||
String[] properties = new String[propertiestag.size()];
|
||||
int j=0;
|
||||
for (Tag propertytag : propertiestag) {
|
||||
properties[j] = propertytag.getName() + "=" + (String) propertytag.getValue();
|
||||
j++;
|
||||
}
|
||||
s += String.join(",", properties);
|
||||
s += "]";
|
||||
}
|
||||
paletteArr[i+1] = s;
|
||||
}
|
||||
section.setPaletteEntries(paletteArr);
|
||||
|
||||
for (int i = 0; i < blocks.size(); i++) {
|
||||
CompoundTag blockTag = blocks.get(i);
|
||||
IntTag stateTag = blockTag.get("state");
|
||||
ListTag posTag = blockTag.get("pos");
|
||||
IntTag xTag = posTag.get(0);
|
||||
IntTag yTag = posTag.get(1);
|
||||
IntTag zTag = posTag.get(2);
|
||||
int x = xTag.getValue();
|
||||
int y = yTag.getValue();
|
||||
int z = zTag.getValue();
|
||||
int storageIdx = width*length*y + width*z + x;
|
||||
|
||||
section.setId(storageIdx, stateTag.getValue()+1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSequence() {
|
||||
if (!loaded || done) {
|
||||
return;
|
||||
}
|
||||
|
||||
String command = section.nextCommand();
|
||||
if (command == null) {
|
||||
done = true;
|
||||
hbot.sendChat("&7Finished building");
|
||||
}
|
||||
else {
|
||||
commandCore.run(command);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,228 @@
|
|||
package com.github.hhhzzzsss.hbot.processes.schem;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.block.Section;
|
||||
import com.github.hhhzzzsss.hbot.util.BlockUtils;
|
||||
import com.github.hhhzzzsss.hbot.util.DownloadUtils;
|
||||
import com.github.steveice10.opennbt.NBTIO;
|
||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class SchemLoaderThread extends Thread {
|
||||
@Getter private final String location;
|
||||
@Getter private Iterable<String> flags;
|
||||
@Getter private int x, y, z;
|
||||
private File schemPath;
|
||||
private URL schemUrl;
|
||||
@Getter private Exception exception;
|
||||
@Getter private String schemName;
|
||||
@Getter private Section section;
|
||||
|
||||
boolean isUrl = false;
|
||||
|
||||
public SchemLoaderThread(int x, int y, int z, String location, Iterable<String> flags) throws IOException {
|
||||
this.location = location;
|
||||
this.flags = flags;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
if (location.startsWith("http://") || location.startsWith("https://")) {
|
||||
isUrl = true;
|
||||
schemUrl = new URL(location);
|
||||
}
|
||||
else if (location.contains("/") || location.contains("\\")) {
|
||||
throw new IOException("Invalid characters in song name: " + location);
|
||||
}
|
||||
else if (getSchemFile(location).exists()) {
|
||||
schemPath = getSchemFile(location);
|
||||
}
|
||||
else if (getSchemFile(location+".schem").exists()) {
|
||||
schemPath = getSchemFile(location+".schem");
|
||||
}
|
||||
else if (getSchemFile(location+".schematic").exists()) {
|
||||
schemPath = getSchemFile(location+".schematic");
|
||||
}
|
||||
else if (getSchemFile(location+".nbt").exists()) {
|
||||
schemPath = getSchemFile(location+".nbt");
|
||||
}
|
||||
else {
|
||||
throw new IOException("Could not find schematic: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
byte[] bytes;
|
||||
if (isUrl) {
|
||||
bytes = DownloadUtils.DownloadToByteArray(schemUrl, 5*1024*1024);
|
||||
schemName = Paths.get(schemUrl.toURI().getPath()).getFileName().toString();
|
||||
}
|
||||
else {
|
||||
bytes = Files.readAllBytes(schemPath.toPath());
|
||||
schemName = schemPath.getName();
|
||||
}
|
||||
|
||||
section = loadSchematic(new ByteArrayInputStream(bytes));
|
||||
|
||||
section.setOrigin(x, y, z);
|
||||
section.cubicOptimize(256);
|
||||
}
|
||||
catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
private File getSchemFile(String name) {
|
||||
return new File(SchemProcess.SCHEM_DIR, name);
|
||||
}
|
||||
|
||||
public Section loadSchematic(InputStream in) throws IOException {
|
||||
CompoundTag nbt;
|
||||
try {
|
||||
Tag tag = NBTIO.readTag(new GZIPInputStream(in));
|
||||
if(!(tag instanceof CompoundTag)) {
|
||||
throw new IOException("Not a valid schematic");
|
||||
}
|
||||
nbt = (CompoundTag) tag;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IOException("Error parsing schematic");
|
||||
}
|
||||
|
||||
if (nbt.contains("BlockData")) {
|
||||
return loadNewSchematic(nbt);
|
||||
}
|
||||
else if (nbt.contains("Blocks")) {
|
||||
return getOldSchematic(nbt);
|
||||
}
|
||||
else if (nbt.contains("blocks")) {
|
||||
return loadStructureSchematic(nbt);
|
||||
}
|
||||
else {
|
||||
throw new IOException("Not a valid schematic");
|
||||
}
|
||||
}
|
||||
|
||||
private Section loadNewSchematic(CompoundTag nbt) {
|
||||
ShortTag widthtag = nbt.get("Width");
|
||||
ShortTag heighttag = nbt.get("Height");
|
||||
ShortTag lengthtag = nbt.get("Length");
|
||||
int width = widthtag.getValue();
|
||||
int height = heighttag.getValue();
|
||||
int length = lengthtag.getValue();
|
||||
Section section = new Section(width, height, length, flags);
|
||||
|
||||
CompoundTag palette = nbt.get("Palette");
|
||||
ByteArrayTag blockdata = nbt.get("BlockData");
|
||||
|
||||
String[] paletteArr = new String[palette.size()];
|
||||
int bpb = 1;
|
||||
while (palette.size() >> bpb > 0) {bpb++;}
|
||||
for (Tag paletteEntry : palette) {
|
||||
IntTag intEntry = (IntTag) paletteEntry;
|
||||
paletteArr[intEntry.getValue()] = intEntry.getName();
|
||||
}
|
||||
section.setPaletteEntries(paletteArr);
|
||||
|
||||
int varInt = 0;
|
||||
int varIntLength = 0;
|
||||
int storageIdx = 0;
|
||||
for (int i = 0; i < blockdata.length(); i++) {
|
||||
varInt |= (int)(blockdata.getValue(i) & 127) << (varIntLength++ * 7);
|
||||
if ((blockdata.getValue(i) & 128) == 128) {
|
||||
continue;
|
||||
}
|
||||
|
||||
section.setId(storageIdx++, varInt);
|
||||
|
||||
varInt = 0;
|
||||
varIntLength = 0;
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
private Section getOldSchematic(CompoundTag nbt) {
|
||||
ShortTag widthtag = nbt.get("Width");
|
||||
ShortTag heighttag = nbt.get("Height");
|
||||
ShortTag lengthtag = nbt.get("Length");
|
||||
int width = widthtag.getValue();
|
||||
int height = heighttag.getValue();
|
||||
int length = lengthtag.getValue();
|
||||
Section section = new Section(width, height, length, flags);
|
||||
|
||||
ByteArrayTag blocks = nbt.get("Blocks");
|
||||
ByteArrayTag data = nbt.get("Data");
|
||||
|
||||
section.setPaletteEntries(BlockUtils.getLegacyIds());
|
||||
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
int legacyId = ((blocks.getValue(i) & 0xff) << 4) + (data.getValue(i) & 0xf);
|
||||
section.setId(i, legacyId);
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
private Section loadStructureSchematic(CompoundTag nbt) {
|
||||
ListTag sizetag = nbt.get("size");
|
||||
IntTag widthtag = sizetag.get(0);
|
||||
IntTag heighttag = sizetag.get(1);
|
||||
IntTag lengthtag = sizetag.get(2);
|
||||
int width = widthtag.getValue();
|
||||
int height = heighttag.getValue();
|
||||
int length = lengthtag.getValue();
|
||||
Section section = new Section(width, height, length, flags);
|
||||
|
||||
ListTag palette = nbt.get("palette");
|
||||
ListTag blocks = nbt.get("blocks");
|
||||
|
||||
String[] paletteArr = new String[palette.size()+1];
|
||||
int bpb = 1;
|
||||
while (paletteArr.length >> bpb > 0) {bpb++;}
|
||||
paletteArr[0] = "minecraft:air";
|
||||
for (int i=0; i<palette.size(); i++) {
|
||||
CompoundTag paletteEntry = palette.get(i);
|
||||
StringTag nametag = paletteEntry.get("Name");
|
||||
String s = nametag.getValue();
|
||||
if (paletteEntry.contains("Properties")) {
|
||||
CompoundTag propertiestag = paletteEntry.get("Properties");
|
||||
s += "[";
|
||||
String[] properties = new String[propertiestag.size()];
|
||||
int j=0;
|
||||
for (Tag propertytag : propertiestag) {
|
||||
properties[j] = propertytag.getName() + "=" + (String) propertytag.getValue();
|
||||
j++;
|
||||
}
|
||||
s += String.join(",", properties);
|
||||
s += "]";
|
||||
}
|
||||
paletteArr[i+1] = s;
|
||||
}
|
||||
section.setPaletteEntries(paletteArr);
|
||||
|
||||
for (int i = 0; i < blocks.size(); i++) {
|
||||
CompoundTag blockTag = blocks.get(i);
|
||||
IntTag stateTag = blockTag.get("state");
|
||||
ListTag posTag = blockTag.get("pos");
|
||||
IntTag xTag = posTag.get(0);
|
||||
IntTag yTag = posTag.get(1);
|
||||
IntTag zTag = posTag.get(2);
|
||||
int x = xTag.getValue();
|
||||
int y = yTag.getValue();
|
||||
int z = zTag.getValue();
|
||||
int storageIdx = width*length*y + width*z + x;
|
||||
|
||||
section.setId(storageIdx, stateTag.getValue()+1);
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.github.hhhzzzsss.hbot.processes.schem;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.HBot;
|
||||
import com.github.hhhzzzsss.hbot.block.Section;
|
||||
import com.github.hhhzzzsss.hbot.command.CommandException;
|
||||
import com.github.hhhzzzsss.hbot.command.PlatformInfo;
|
||||
import com.github.hhhzzzsss.hbot.commandcore.CommandCore;
|
||||
import com.github.hhhzzzsss.hbot.commandcore.CoreProcess;
|
||||
|
||||
public class SchemProcess extends CoreProcess {
|
||||
private HBot hbot;
|
||||
private CommandCore commandCore;
|
||||
private PlatformInfo platform;
|
||||
Section section;
|
||||
|
||||
SchemLoaderThread loaderThread;
|
||||
|
||||
boolean loaded = false;
|
||||
|
||||
public static final File SCHEM_DIR = new File("schematics");
|
||||
static {
|
||||
if (!SCHEM_DIR.exists()) {
|
||||
SCHEM_DIR.mkdir();
|
||||
}
|
||||
}
|
||||
|
||||
public SchemProcess(HBot hbot, PlatformInfo platform, int x, int y, int z, String location, Iterable<String> flags) throws CommandException {
|
||||
this.hbot = hbot;
|
||||
commandCore = hbot.getCommandCore();
|
||||
this.platform = platform;
|
||||
|
||||
try {
|
||||
loaderThread = new SchemLoaderThread(x, y, z, location, flags);
|
||||
} catch (IOException e) {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
loaderThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSequence() {
|
||||
if (done) return;
|
||||
|
||||
if (!loaded) {
|
||||
if (!loaderThread.isAlive()) {
|
||||
if (loaderThread.getSection() != null) {
|
||||
section = loaderThread.getSection();
|
||||
platform.sendMessage("&7Now building &3" + loaderThread.getSchemName());
|
||||
loaded = true;
|
||||
} else if (loaderThread.getException() != null) {
|
||||
hbot.sendChat("&cError while loading schematic: &4" + loaderThread.getException().getMessage());
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String command = section.nextCommand();
|
||||
if (command == null) {
|
||||
done = true;
|
||||
hbot.sendChat("&7Finished building");
|
||||
}
|
||||
else {
|
||||
commandCore.run(command);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +1,15 @@
|
|||
package com.github.hhhzzzsss.hbot.subBots;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.github.hhhzzzsss.hbot.Bot;
|
||||
import com.github.hhhzzzsss.hbot.entity.EntityTracker;
|
||||
import com.github.hhhzzzsss.hbot.entity.PlayerEntity;
|
||||
import com.github.hhhzzzsss.hbot.util.ChatUtils;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundChatPacket;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import lombok.Getter;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OrbitBot extends Bot {
|
||||
@Getter Bot parent;
|
||||
|
@ -103,8 +102,8 @@ public class OrbitBot extends Bot {
|
|||
|
||||
@Override
|
||||
protected void onPacket(Packet packet) {
|
||||
if (packet instanceof ServerChatPacket) {
|
||||
ServerChatPacket t_packet = (ServerChatPacket) packet;
|
||||
if (packet instanceof ClientboundChatPacket) {
|
||||
ClientboundChatPacket t_packet = (ClientboundChatPacket) packet;
|
||||
String text = ChatUtils.getFullText(t_packet.getMessage());
|
||||
if (text.equals("Error: Player not found.") || text.equals("Error: null.")) {
|
||||
sendChatInstantly("Could not teleport to target. Disconnecting...");
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.github.hhhzzzsss.hbot.Main
|
||||
|
|
@ -4,7 +4,7 @@ This file will explain what the different resources are and where they come from
|
|||
## mapColors.json
|
||||
Map color data contains the colors of various blocks when they appear on maps. Currently, the data I've pulled contains a block for every color except for the color corresponding to water.
|
||||
|
||||
The map color data is taken from [MapartCraft](https://rebane2001.com/mapartcraft/). The data for the selected blocks is pulled into a json file with the following script:
|
||||
The map color data is taken from [MapartCraft](https://rebane2001.com/mapartcraft/). The data for the selected blocks used to be pulled into a json file with the following script:
|
||||
|
||||
```javascript
|
||||
function download(filename, text) {
|
||||
|
@ -35,6 +35,8 @@ mapdata.push({
|
|||
download ('mapColors.json', JSON.stringify(mapdata, null, 2));
|
||||
```
|
||||
|
||||
But ever since they rewrote their site in react, it became impossible to extract the json from the Javascript console, so I wrote a new program that can extract it from their coloursJSON.json file here: [https://github.com/hhhzzzsss/MapartCraftPresetExtractor](https://github.com/hhhzzzsss/MapartCraftPresetExtractor).
|
||||
|
||||
## blocks.json, entities.json, language.json
|
||||
These files are from [https://github.com/PrismarineJS/minecraft-data](https://github.com/PrismarineJS/minecraft-data).
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ bots:
|
|||
serverNick: "Kaboom"
|
||||
discordToken: "Discord bot token goes here"
|
||||
categoryName: "Main Kaboom Channels"
|
||||
isDefault: true
|
||||
|
||||
trustedKey: ""
|
||||
adminKey: ""
|
||||
|
|
Loading…
Reference in a new issue