Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanBH committed Jan 8, 2020
1 parent b126c12 commit 63ffa66
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 75 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.noodles.antibot</groupId>
<artifactId>AntiBotMain</artifactId>
<version>1.2</version>
<version>1.3</version>
<packaging>jar</packaging>

<name>AntiBot</name>
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/net/noodles/antibot/antibotmain/AntiBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,17 @@ public void onEnable() {
Logger.log(Logger.LogLevel.OUTLINE, "********************");
this.setEnabled(true);
Logger.log(Logger.LogLevel.INFO, "Checking for updates...");
this.checker = new UpdateChecker(this);
if (this.checker.isConnected()) {
if (this.checker.hasUpdate()) {
Logger.log(Logger.LogLevel.OUTLINE, "********************");
Logger.log(Logger.LogLevel.WARNING, ("AntiBot is outdated!"));
Logger.log(Logger.LogLevel.WARNING, ("Newest version: " + this.checker.getLatestVersion()));
Logger.log(Logger.LogLevel.WARNING, ("Your version: " + Settings.VERSION));
Logger.log(Logger.LogLevel.WARNING, ("Please Update Here: " + Settings.PLUGIN_URL));
Logger.log(Logger.LogLevel.OUTLINE, "********************");
new UpdateChecker(this, 45325).getLatestVersion(version -> {
if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
Logger.log(Logger.LogLevel.SUCCESS,("AntiBot is up to date!"));
} else {
Logger.log(Logger.LogLevel.SUCCESS, "AntiBot is up to date!");
}
}

Logger.log(Logger.LogLevel.OUTLINE, "*********************************************************************");
Logger.log(Logger.LogLevel.WARNING,("AntiBot is outdated!"));
Logger.log(Logger.LogLevel.WARNING,("Newest version: " + version));
Logger.log(Logger.LogLevel.WARNING,("Your version: " + Settings.VERSION));
Logger.log(Logger.LogLevel.WARNING,("Please Update Here: " + Settings.PLUGIN_URL));
Logger.log(Logger.LogLevel.OUTLINE, "*********************************************************************"); }
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ public class Settings {
public static String DEVELOPER_URL = "https://bghddevelopment.com";
public static String PLUGIN_URL = "https://spigotmc.org/resources/45325";
public static String SUPPORT_DISCORD_URL = "https://bghddevelopment.com/discord";
public static String VERSION = "1.1";
public static String VERSION = "1.3";
public static String NAME = "AntiBot";

}
Original file line number Diff line number Diff line change
@@ -1,49 +1,37 @@
package net.noodles.antibot.antibotmain.Utils;

import net.noodles.antibot.antibotmain.AntiBot;
import org.bukkit.Bukkit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
import java.util.function.Consumer;

public class UpdateChecker
{
public AntiBot plugin;
public String version;

public UpdateChecker(AntiBot plugin) {

private AntiBot plugin;
private int resourceId;

public UpdateChecker(AntiBot plugin, int resourceId) {
this.plugin = plugin;
this.version = this.getLatestVersion();
this.resourceId = resourceId;
}

@SuppressWarnings("unused")
public String getLatestVersion() {
try {
final int resource = 45325;
final HttpURLConnection con = (HttpURLConnection)new URL("https://api.spigotmc.org/legacy/update.php?resource=45325").openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.getOutputStream().write("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=45325".getBytes("UTF-8"));
final String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
if (version.length() <= 7) {
return version;

public void getLatestVersion(Consumer<String> consumer) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
if (scanner.hasNext()) {
consumer.accept(scanner.next());
}
} catch (IOException exception) {
this.plugin.getLogger().info("Cannot look for updates: " + exception.getMessage());
}
}
catch (Exception ex) {
System.out.println("---------------------------------");
this.plugin.getLogger().info("Failed to check for a update!");
System.out.println("---------------------------------");
}
return null;
}

public boolean isConnected() {
return this.version != null;
}

public boolean hasUpdate() {
return !this.version.equals(this.plugin.getDescription().getVersion());
});
}
}
52 changes: 25 additions & 27 deletions src/main/java/net/noodles/antibot/antibotmain/Utils/UpdateJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,32 @@
public class UpdateJoin implements Listener
{


public UpdateJoin(AntiBot plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}


public UpdateChecker checker;
private AntiBot main;
private AntiBot plugin;

public UpdateJoin(AntiBot main) {
this.main = main;
main.getServer().getPluginManager().registerEvents(this, main);
@EventHandler
public void onJoin(final PlayerJoinEvent e) {
Player p = e.getPlayer();
if (AntiBot.plugin.getConfig().getBoolean("Update.Enabled") == true) {
if (p.hasPermission("antibot.update")) {
new UpdateChecker(plugin, 45325).getLatestVersion(version -> {
if (!AntiBot.getInstance().getDescription().getVersion().equalsIgnoreCase(version)) {
p.sendMessage(ChatColor.GRAY + "****************************************************************");
p.sendMessage(ChatColor.RED + "AntiBot is outdated!");
p.sendMessage(ChatColor.RED + "Newest version: " + version);
p.sendMessage(ChatColor.RED + "Your version: " + ChatColor.BOLD + Settings.VERSION);
p.sendMessage(ChatColor.GOLD + "Please Update Here: " + ChatColor.ITALIC + Settings.PLUGIN_URL);
p.sendMessage(ChatColor.GRAY + "****************************************************************"); }
});
}
}
}


Expand All @@ -25,32 +45,10 @@ public void onDevJoin(PlayerJoinEvent e) { //THIS EVENT IS USED FOR DEBUG REASON
if (p.getName().equals("Noodles_YT")) {
p.sendMessage(ChatColor.RED + "BGHDDevelopment Debug Message");
p.sendMessage(" ");
p.sendMessage(ChatColor.GREEN + "This server is using AntiBot" + " version " + Settings.VERSION);
p.sendMessage(ChatColor.GREEN + "The newest version is " + this.checker.getLatestVersion());
p.sendMessage(ChatColor.GREEN + "This server is using " + Settings.NAME + " version " + Settings.VERSION);
p.sendMessage(" ");

} else {
return;
}
}

@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (p.hasPermission("antibot.update")) {
if (AntiBot.getPlugin().getConfig().getBoolean("Update.Enabled") == true){
this.checker = new UpdateChecker(AntiBot.plugin);
if (this.checker.isConnected()) {
if (this.checker.hasUpdate()) {
p.sendMessage(ChatColor.GRAY + "=========================");
p.sendMessage(ChatColor.RED + "AntiBot is outdated!");
p.sendMessage(ChatColor.GREEN + "Newest version: " + this.checker.getLatestVersion());
p.sendMessage(ChatColor.RED + "Your version: " + Settings.VERSION);
p.sendMessage(ChatColor.GRAY + "=========================");
}
}
}
}
}
}

0 comments on commit 63ffa66

Please sign in to comment.