Skip to content

Commit

Permalink
Merge pull request #85 from mrgeneralq/updater-fix
Browse files Browse the repository at this point in the history
Updater fix
  • Loading branch information
mrgeneralq committed May 2, 2021
2 parents 4b0f779 + 3ac0501 commit ea73998
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 136 deletions.
240 changes: 123 additions & 117 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,118 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.mrgeneralq</groupId>
<artifactId>sleep-most</artifactId>
<version>4.8.2</version>
<name>SleepMost</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
<java.version>8</java.version>
<shade.base>me.mrgeneralq.sleepmost</shade.base>
<dir>${project.build.directory}</dir>
</properties>
<build>
<testSourceDirectory>src/main/tests</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>${dir}\server\plugins</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<!-- Do not include the <configuration>...</configuration> part if you are using Sponge! -->
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>org.bstats.bukkit</pattern>
<shadedPattern>${shade.base}.bstats</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

</build>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
<scope>provided</scope>
</dependency>
</dependencies>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.mrgeneralq</groupId>
<artifactId>sleep-most</artifactId>
<version>4.8.1</version>
<name>SleepMost</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
<java.version>8</java.version>
<shade.base>me.mrgeneralq.sleepmost</shade.base>
<dir>${project.build.directory}</dir>
</properties>
<build>
<testSourceDirectory>src/main/tests</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>${dir}\server\plugins</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<!-- Do not include the <configuration>...</configuration> part if you are using Sponge! -->
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>org.bstats.bukkit</pattern>
<shadedPattern>${shade.base}.bstats</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
<scope>provided</scope>
</dependency>

</dependencies>
</project>
2 changes: 2 additions & 0 deletions src/main/java/me/mrgeneralq/sleepmost/Sleepmost.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.mrgeneralq.sleepmost.eventlisteners.*;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -13,6 +14,7 @@

public class Sleepmost extends JavaPlugin{


@Override
public void onEnable() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public interface IUpdateService {

boolean hasUpdate();
boolean hasUpdate(String version);

String getCurrentVersion();
String getCachedUpdateVersion();
}
34 changes: 30 additions & 4 deletions src/main/java/me/mrgeneralq/sleepmost/services/UpdateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import me.mrgeneralq.sleepmost.interfaces.IUpdateRepository;
import me.mrgeneralq.sleepmost.interfaces.IUpdateService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


public class UpdateService implements IUpdateService {
Expand All @@ -23,8 +27,14 @@ public UpdateService(IUpdateRepository updateRepository, Sleepmost main, IConfig
this.configService = configService;
}


@Override
public boolean hasUpdate() {
return hasUpdate(this.getCurrentVersion());
}

@Override
public boolean hasUpdate(String version) {

if(!configService.updateCheckerEnabled()){
return false;
Expand All @@ -46,18 +56,34 @@ public boolean hasUpdate() {
}

if(cachedUpdateVersion == null)
return false;
return false;


if(cachedUpdateVersion.equals(version))
return false;

try{
int currentVersion = Integer.parseInt(getCurrentVersion().replaceAll("\\.",""));
int cachedVersion = Integer.parseInt(this.cachedUpdateVersion.replaceAll("\\.",""));

return cachedVersion > currentVersion;
List<Integer> splittedCurrentVersion = Arrays.stream(getCurrentVersion().split("\\.")).map(Integer::parseInt).collect(Collectors.toList());
List<Integer> splittedCachedVersion = Arrays.stream(this.cachedUpdateVersion.split("\\.")).map(Integer::parseInt).collect(Collectors.toList());


for(int i = 0; i < splittedCachedVersion.size(); i ++){

Integer current = splittedCurrentVersion.get(i);
Integer cached = splittedCachedVersion.get(i);

if(current > cached)
return false;

}

return true;

}catch(Exception ex){
return false;
}

}

@Override
Expand Down
Loading

0 comments on commit ea73998

Please sign in to comment.