Skip to content

Commit

Permalink
Update to v1.3.2, implement pause time in anti push & check verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablete1234 committed Sep 20, 2020
1 parent 3ab3a7d commit 90b5a8b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
30 changes: 25 additions & 5 deletions src/main/java/eu/darkbot/popcorn/def/AntiPush.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,58 @@
package eu.darkbot.popcorn.def;

import com.github.manolo8.darkbot.Main;
import com.github.manolo8.darkbot.config.types.Num;
import com.github.manolo8.darkbot.config.types.Option;
import com.github.manolo8.darkbot.core.entities.Ship;
import com.github.manolo8.darkbot.core.itf.Behaviour;
import com.github.manolo8.darkbot.core.itf.Configurable;
import com.github.manolo8.darkbot.core.manager.EffectManager;
import com.github.manolo8.darkbot.core.manager.MapManager;
import com.github.manolo8.darkbot.extensions.features.Feature;
import com.github.manolo8.darkbot.modules.DisconnectModule;
import com.github.manolo8.darkbot.utils.I18n;

import java.util.Arrays;
import java.util.List;

@Feature(name = "Anti push", description = "Turns off the bot if an enemy uses draw fire", enabledByDefault = true)
public class AntiPush implements Behaviour {
public class AntiPush implements Behaviour, Configurable<AntiPush.Config> {

private MapManager mapManager;
private List<Ship> ships;
private Main main;
private Config config;

public static class Config {
@Option(value = "Pause Time (minutes)", description = "Pause time, 0 for infinite pause")
@Num(min = 0, max = 300)
public int PAUSE_TIME = 0;
}

@Override
public void install(Main main) {
if (!Arrays.equals(VerifierChecker.class.getSigners(), getClass().getSigners())) return;
VerifierChecker.checkAuthenticity();
this.main = main;
this.mapManager = main.mapManager;
this.ships = main.mapManager.entities.ships;
}

@Override
public void setConfig(Config config) {
this.config = config;
}

@Override
public void tick() {
for (Ship ship : ships) {
if (ship.playerInfo.isEnemy() && ship.hasEffect(EffectManager.Effect.DRAW_FIRE) && mapManager.isTarget(ship)) {
System.out.println("Paused bot, enemy used draw fire");
main.setModule(new DisconnectModule(null, I18n.get("module.disconnect.reason.draw_fire")));
}
if (!ship.playerInfo.isEnemy() || !ship.hasEffect(EffectManager.Effect.DRAW_FIRE) || !mapManager.isTarget(ship)) continue;
System.out.println("Pausing bot" +
(config.PAUSE_TIME > 0 ? " for " + config.PAUSE_TIME + " minutes" : "") +
", enemy used draw fire");

Long pauseMillis = config.PAUSE_TIME > 0 ? (long) config.PAUSE_TIME * 60 * 1000 : null;
main.setModule(new DisconnectModule(pauseMillis, I18n.get("module.disconnect.reason.draw_fire")));
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/eu/darkbot/popcorn/def/PalladiumModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.github.manolo8.darkbot.modules.LootNCollectorModule;
import com.github.manolo8.darkbot.modules.MapModule;

import java.util.Arrays;
import java.util.List;

@Feature(name = "Palladium Module", description = "Loot & collect, but when full cargo is full travels to 5-2 to sell")
Expand Down Expand Up @@ -40,6 +41,7 @@ public String instructions() {

@Override
public void install(Main main) {
if (!Arrays.equals(VerifierChecker.class.getSigners(), getClass().getSigners())) return;
VerifierChecker.checkAuthenticity();
super.install(main);
this.SELL_MAP = main.starManager.byName("5-2");
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/eu/darkbot/popcorn/def/SampleModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.github.manolo8.darkbot.extensions.features.Feature;
import com.github.manolo8.darkbot.gui.tree.components.JPercentField;
import com.github.manolo8.darkbot.gui.utils.Popups;
import com.github.manolo8.darkbot.utils.AuthAPI;

import javax.swing.*;
import java.util.Arrays;
Expand All @@ -37,7 +38,21 @@ public class SampleModule implements
*/
@Override
public void install(Main main) {
VerifierChecker.checkAuthenticity(); // Check for verifier authenticity
// Ensure that the verifier is from this plugin and properly signed by yourself
// If it isn't don't install for this main.
if (!Arrays.equals(VerifierChecker.class.getSigners(), getClass().getSigners())) return;

AuthAPI api = VerifierChecker.getAuthApi();

// If the user isn't verified, setup auth.
// This should be done regardless of if you enforce donors-only on your modules
if (!api.isAuthenticated()) api.setupAuth();

// Alternatively if you want to enforce donors-only on your features, use this instead
// You should not do both, as requireDonor will take care of setting up auth
//if (!VerifierChecker.getAuthApi().requireDonor()) return;


this.drive = main.hero.drive;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "Default plugin",
"author": "Popcorn",
"version": "1.3.1",
"version": "1.3.2",
"minVersion": "1.13.17 beta 36",
"supportedVersion": "1.13.17 beta 36",
"features": [
"eu.darkbot.popcorn.def.PalladiumModule",
"eu.darkbot.popcorn.def.AntiPush",
"eu.darkbot.popcorn.def.SampleModule"
],
"download": "https://github.com/darkbot-reloaded/DefaultPlugin/releases/download/v1.3.1/DefaultPlugin.jar",
"download": "https://github.com/darkbot-reloaded/DefaultPlugin/releases/download/v1.3.2/DefaultPlugin.jar",
"update": "https://raw.githubusercontent.com/darkbot-reloaded/DefaultPlugin/master/src/main/resources/plugin.json"
}

0 comments on commit 90b5a8b

Please sign in to comment.