Skip to content

Commit f0236f3

Browse files
authored
Merge pull request #123 from MrKinau/2.7.15
2.7.15
2 parents 54b0110 + 3660e3f commit f0236f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1086
-241
lines changed

pom.xml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
<groupId>systems.kinau</groupId>
1313
<artifactId>FishingBot</artifactId>
14-
<version>2.7.14</version>
14+
<version>2.7.15</version>
1515
<name>FishingBot</name>
16-
<description>An AFK fishing bot for minecraft</description>
16+
<description>An AFK fishing bot for Minecraft</description>
1717

1818
<properties>
1919
<jar.finalName>Fishingbot</jar.finalName>
@@ -26,6 +26,10 @@
2626
<id>bintray-jcenter</id>
2727
<url>https://jcenter.bintray.com</url>
2828
</repository>
29+
<repository>
30+
<id>jitpack.io</id>
31+
<url>https://jitpack.io</url>
32+
</repository>
2933
</repositories>
3034

3135
<dependencies>
@@ -86,6 +90,11 @@
8690
<artifactId>javax.annotation-api</artifactId>
8791
<version>1.3.2</version>
8892
</dependency>
93+
<dependency>
94+
<groupId>com.github.GeyserMC</groupId>
95+
<artifactId>MCAuthLib</artifactId>
96+
<version>0e48a094f2</version>
97+
</dependency>
8998

9099
<!-- JAVAFX -->
91100
<dependency>
@@ -124,7 +133,11 @@
124133
<version>15.0.1</version>
125134
<classifier>mac</classifier>
126135
</dependency>
127-
136+
<dependency>
137+
<groupId>org.slf4j</groupId>
138+
<artifactId>slf4j-jdk14</artifactId>
139+
<version>1.7.25</version>
140+
</dependency>
128141
</dependencies>
129142

130143
<build>
@@ -152,7 +165,7 @@
152165
<artifactId>javafx-maven-plugin</artifactId>
153166
<version>0.0.4</version>
154167
<configuration>
155-
<mainClass>systems.kinau.fishingbot.gui.MainGUI</mainClass>
168+
<mainClass>systems.kinau.fishingbot.Main</mainClass>
156169
</configuration>
157170
</plugin>
158171

src/main/java/systems/kinau/fishingbot/Bot.java

Lines changed: 67 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
import systems.kinau.fishingbot.auth.AuthData;
1212
import systems.kinau.fishingbot.auth.Authenticator;
1313
import systems.kinau.fishingbot.bot.Player;
14+
import systems.kinau.fishingbot.bot.loot.LootHistory;
1415
import systems.kinau.fishingbot.event.EventManager;
1516
import systems.kinau.fishingbot.gui.Dialogs;
17+
import systems.kinau.fishingbot.gui.GUIController;
1618
import systems.kinau.fishingbot.i18n.I18n;
1719
import systems.kinau.fishingbot.io.config.SettingsConfig;
1820
import systems.kinau.fishingbot.io.logging.LogFormatter;
19-
import systems.kinau.fishingbot.modules.ChatProxyModule;
20-
import systems.kinau.fishingbot.modules.ClientDefaultsModule;
21-
import systems.kinau.fishingbot.modules.HandshakeModule;
22-
import systems.kinau.fishingbot.modules.LoginModule;
21+
import systems.kinau.fishingbot.modules.*;
2322
import systems.kinau.fishingbot.modules.command.ChatCommandModule;
2423
import systems.kinau.fishingbot.modules.command.CommandRegistry;
2524
import systems.kinau.fishingbot.modules.command.commands.*;
2625
import systems.kinau.fishingbot.modules.discord.DiscordModule;
2726
import systems.kinau.fishingbot.modules.ejection.EjectionModule;
2827
import systems.kinau.fishingbot.modules.fishing.FishingModule;
2928
import systems.kinau.fishingbot.modules.fishing.ItemHandler;
29+
import systems.kinau.fishingbot.modules.timer.TimerModule;
3030
import systems.kinau.fishingbot.network.ping.ServerPinger;
3131
import systems.kinau.fishingbot.network.protocol.NetworkHandler;
3232
import systems.kinau.fishingbot.network.protocol.ProtocolConstants;
@@ -38,6 +38,7 @@
3838
import java.net.Socket;
3939
import java.util.Arrays;
4040
import java.util.List;
41+
import java.util.Optional;
4142
import java.util.concurrent.atomic.AtomicBoolean;
4243
import java.util.logging.FileHandler;
4344

@@ -55,11 +56,9 @@ public class Bot {
5556

5657
@Getter private EventManager eventManager;
5758
@Getter private CommandRegistry commandRegistry;
59+
@Getter private ModuleManager moduleManager;
5860

5961
@Getter private Player player;
60-
@Getter private ClientDefaultsModule clientModule;
61-
@Getter private ChatProxyModule chatProxyModule;
62-
@Getter private EjectionModule ejectModule;
6362

6463
@Getter private Socket socket;
6564
@Getter private NetworkHandler net;
@@ -72,6 +71,7 @@ public class Bot {
7271
public Bot(CommandLine cmdLine) {
7372
FishingBot.getInstance().setCurrentBot(this);
7473
this.eventManager = new EventManager();
74+
this.moduleManager = new ModuleManager();
7575
if (!cmdLine.hasOption("nogui"))
7676
getEventManager().registerListener(FishingBot.getInstance().getMainGUIController());
7777

@@ -132,9 +132,16 @@ public Bot(CommandLine cmdLine) {
132132
}
133133

134134
// authenticate player if online-mode is set
135-
if(getConfig().isOnlineMode())
136-
authenticate(accountFile);
137-
else {
135+
if (getConfig().isOnlineMode()) {
136+
boolean authSuccessful = authenticate(accountFile);
137+
if (!authSuccessful) {
138+
setPreventStartup(true);
139+
FishingBot.getI18n().severe("credentials-invalid");
140+
if (!cmdLine.hasOption("nogui")) {
141+
Dialogs.showCredentialsInvalid(GUIController::openWebpage);
142+
}
143+
}
144+
} else {
138145
FishingBot.getI18n().info("credentials-using-offline-mode", getConfig().getUserName());
139146
this.authData = new AuthData(null, null, null, getConfig().getUserName());
140147
}
@@ -241,6 +248,18 @@ public Bot(CommandLine cmdLine) {
241248
sp.ping();
242249
}
243250

251+
public FishingModule getFishingModule() {
252+
return (FishingModule) getModuleManager().getLoadedModule(FishingModule.class).orElse(null);
253+
}
254+
255+
public EjectionModule getEjectModule() {
256+
return (EjectionModule) getModuleManager().getLoadedModule(EjectionModule.class).orElse(null);
257+
}
258+
259+
public DiscordModule getDiscordModule() {
260+
return (DiscordModule) getModuleManager().getLoadedModule(DiscordModule.class).orElse(null);
261+
}
262+
244263
public void start() {
245264
if (isRunning() || isPreventStartup()) {
246265
FishingBot.getInstance().setCurrentBot(null);
@@ -253,14 +272,14 @@ public void start() {
253272

254273
private boolean authenticate(File accountFile) {
255274
Authenticator authenticator = new Authenticator(accountFile);
256-
AuthData authData = authenticator.authenticate();
275+
Optional<AuthData> authData = authenticator.authenticate(getConfig().getAuthService());
257276

258-
if (authData == null) {
277+
if (!authData.isPresent()) {
259278
setAuthData(new AuthData(null, null, null, getConfig().getUserName()));
260279
return false;
261280
}
262281

263-
setAuthData(authData);
282+
setAuthData(authData.get());
264283
return true;
265284
}
266285

@@ -273,12 +292,16 @@ private void registerCommands() {
273292
getCommandRegistry().registerCommand(new StuckCommand());
274293
getCommandRegistry().registerCommand(new DropRodCommand());
275294
getCommandRegistry().registerCommand(new LookCommand());
295+
getCommandRegistry().registerCommand(new SummaryCommand());
296+
getCommandRegistry().registerCommand(new RightClickCommand());
276297
}
277298

278299
private void connect() {
279300
String serverName = getServerHost();
280301
int port = getServerPort();
281302

303+
LootHistory savedLootHistory = new LootHistory();
304+
282305
do {
283306
try {
284307
setRunning(true);
@@ -300,27 +323,39 @@ private void connect() {
300323
this.net = new NetworkHandler();
301324

302325
registerCommands();
326+
if (FishingBot.getInstance().getMainGUIController() != null)
327+
getEventManager().registerListener(FishingBot.getInstance().getMainGUIController());
328+
329+
if (FishingBot.getInstance().getMainGUIController() != null && !getEventManager().isRegistered(FishingBot.getInstance().getMainGUIController()))
330+
getEventManager().registerListener(FishingBot.getInstance().getMainGUIController());
303331

304-
this.fishingModule = new FishingModule();
305-
getFishingModule().enable();
332+
// enable required modules
333+
334+
getModuleManager().enableModule(new HandshakeModule(serverName, port));
335+
getModuleManager().enableModule(new LoginModule(getAuthData().getUsername()));
336+
getModuleManager().enableModule(new ClientDefaultsModule());
337+
getModuleManager().enableModule(new FishingModule(savedLootHistory));
338+
getModuleManager().enableModule(new ChatProxyModule());
306339

307-
new HandshakeModule(serverName, port).enable();
308-
new LoginModule(getAuthData().getUsername()).enable();
309-
this.chatProxyModule = new ChatProxyModule();
310-
getChatProxyModule().enable();
311340
if (getConfig().isStartTextEnabled())
312-
new ChatCommandModule().enable();
313-
this.clientModule = new ClientDefaultsModule();
314-
getClientModule().enable();
341+
getModuleManager().enableModule(new ChatCommandModule());
342+
315343
if (getConfig().isWebHookEnabled())
316-
new DiscordModule().enable();
317-
if (getConfig().isAutoLootEjectionEnabled()) {
318-
this.ejectModule = new EjectionModule();
319-
getEjectModule().enable();
320-
}
344+
getModuleManager().enableModule(new DiscordModule());
345+
346+
if (getConfig().isAutoLootEjectionEnabled())
347+
getModuleManager().enableModule(new EjectionModule());
348+
349+
if (getConfig().isTimerEnabled())
350+
getModuleManager().enableModule(new TimerModule());
351+
352+
// init item handler & player
353+
321354
new ItemHandler(getServerProtocol());
322355
this.player = new Player();
323356

357+
// add shutdown hook
358+
324359
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
325360
try {
326361
if (socket != null && !socket.isClosed())
@@ -330,6 +365,8 @@ private void connect() {
330365
}
331366
}));
332367

368+
// game loop (for receiving packets)
369+
333370
while (running) {
334371
try {
335372
net.readData();
@@ -350,20 +387,14 @@ private void connect() {
350387
e.printStackTrace();
351388
}
352389

353-
if (getClientModule() != null)
354-
getClientModule().disable();
355-
if (getFishingModule() != null)
356-
getFishingModule().disable();
357-
if (getChatProxyModule() != null)
358-
getChatProxyModule().disable();
359-
if (getEjectModule() != null)
360-
getEjectModule().disable();
361390
if (getPlayer() != null)
362391
getEventManager().unregisterListener(getPlayer());
363392
getEventManager().getRegisteredListener().clear();
364393
getEventManager().getClassToInstanceMapping().clear();
394+
if (getFishingModule() != null)
395+
savedLootHistory = getFishingModule().getLootHistory();
396+
getModuleManager().disableAll();
365397
this.socket = null;
366-
this.fishingModule = null;
367398
this.net = null;
368399
this.player = null;
369400
}

src/main/java/systems/kinau/fishingbot/FishingBot.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import lombok.Getter;
44
import lombok.Setter;
55
import org.apache.commons.cli.CommandLine;
6+
import systems.kinau.fishingbot.event.custom.BotStartEvent;
7+
import systems.kinau.fishingbot.event.custom.BotStopEvent;
68
import systems.kinau.fishingbot.gui.GUIController;
79
import systems.kinau.fishingbot.gui.MainGUI;
810
import systems.kinau.fishingbot.i18n.I18n;
@@ -76,12 +78,14 @@ public void startBot() {
7678
stopBot(true);
7779
Thread.currentThread().setName("mainThread");
7880
Bot bot = new Bot(cmdLine);
81+
bot.getEventManager().callEvent(new BotStartEvent());
7982
bot.start();
8083
}
8184

8285
public void stopBot(boolean preventReconnect) {
8386
if (getCurrentBot() == null)
8487
return;
88+
FishingBot.getInstance().getCurrentBot().getEventManager().callEvent(new BotStopEvent());
8589
// TODO: Send Disconnect Packet
8690
getCurrentBot().setPreventReconnect(preventReconnect);
8791
getCurrentBot().setRunning(false);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package systems.kinau.fishingbot.auth;
2+
3+
public enum AuthService {
4+
MOJANG,
5+
MICROSOFT
6+
}

0 commit comments

Comments
 (0)