Skip to content

Commit

Permalink
Update VersionDelimiter to support classifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldexun committed Mar 6, 2023
1 parent ffccbe7 commit 2fc97db
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 76 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/charles445/rltweaker/RLTweaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class RLTweaker
public static final String MODID = "rltweaker";
public static final String NAME = "RLTweaker";
public static final String VERSION = "0.5.8";
public static final VersionDelimiter VERSION_DELIMITER = new VersionDelimiter(VERSION);
public static final VersionDelimiter VERSION_DELIMITER = VersionDelimiter.parse(VERSION);

@Mod.Instance(RLTweaker.MODID)
public static RLTweaker instance;
Expand Down Expand Up @@ -339,11 +339,11 @@ public boolean checkVersion(Map<String, String> values, Side side)
//System.out.println("checkVersion SERVER");
if(StringUtils.isEmpty(version))
{
NetworkHandler.serverVersion = new VersionDelimiter("0.0.0");
NetworkHandler.serverVersion = VersionDelimiter.UNKOWN;
}
else
{
VersionDelimiter servervd = new VersionDelimiter(version);
VersionDelimiter servervd = VersionDelimiter.parse(version);
NetworkHandler.serverVersion = servervd;
if(servervd.isSameOrNewerVersion(0, 4))
{
Expand All @@ -362,11 +362,11 @@ public boolean checkVersion(Map<String, String> values, Side side)
//System.out.println("checkVersion CLIENT");
if(StringUtils.isEmpty(version))
{
RLTweaker.logger.trace("Client Version: "+new VersionDelimiter("0.0.0"));
RLTweaker.logger.trace("Client Version: "+VersionDelimiter.UNKOWN);
}
else
{
RLTweaker.logger.trace("Client Version: "+new VersionDelimiter(version));
RLTweaker.logger.trace("Client Version: "+VersionDelimiter.parse(version));
}

RLTweaker.logger.trace("Local Version: "+VERSION_DELIMITER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public SMEHandler()
//Get the version to decide what to do next
Class c_somanyenchantments = Class.forName("com.Shultrea.Rin.Main_Sector.somanyenchantments");
Field f_version = ReflectUtil.findField(c_somanyenchantments, "VERSION");
VersionDelimiter vd = new VersionDelimiter((String)f_version.get(null));
VersionDelimiter vd = VersionDelimiter.parse((String)f_version.get(null));

if(vd.isSameOrNewerVersion(0, 5))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MessageUpdateAttackYaw implements IMessage
{
private float attackedAtYaw;

public static final VersionDelimiter VERSION = new VersionDelimiter("0.4.0");
public static final VersionDelimiter VERSION = VersionDelimiter.parse("0.4.0");

public MessageUpdateAttackYaw()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class NetworkHandler
{
public static boolean serverHasVersioning = false;
public static VersionDelimiter serverVersion = new VersionDelimiter("0.0.0");
public static VersionDelimiter serverVersion = VersionDelimiter.UNKOWN;

//Accessed by Netty a lot
private static Map<UUID, VersionDelimiter> clients = new ConcurrentHashMap<>();
Expand Down
128 changes: 60 additions & 68 deletions src/main/java/com/charles445/rltweaker/util/VersionDelimiter.java
Original file line number Diff line number Diff line change
@@ -1,90 +1,82 @@
package com.charles445.rltweaker.util;

public class VersionDelimiter
{
public int major;
public int minor;
public int patch;

public VersionDelimiter(String ss)
{
if(ss==null || ss.isEmpty())
{
wipeVersion();
return;
}

String[] split = ss.split("\\.");

if(split.length!=3)
{
wipeVersion();
return;
}

try
{
this.major = Integer.parseInt(split[0]);
this.minor = Integer.parseInt(split[1]);
this.patch = Integer.parseInt(split[2]);
}
catch(NumberFormatException e)
{
wipeVersion();
return;
}
import javax.annotation.Nullable;

public class VersionDelimiter {

public static final VersionDelimiter UNKOWN = new VersionDelimiter(0, 0, 0, null);
public final int major;
public final int minor;
public final int patch;
public final String classifier;

public VersionDelimiter(int major, int minor, int patch) {
this(major, minor, patch, null);
}

public VersionDelimiter(int major, int minor, int patch)
{

public VersionDelimiter(int major, int minor, int patch, @Nullable String classifier) {
this.major = major;
this.minor = minor;
this.patch = patch;
this.classifier = classifier;
}

public static VersionDelimiter parse(String s) {
if (s == null || s.isEmpty()) {
return UNKOWN;
}

int i = s.indexOf('-');
return i != -1 ? parse(s.substring(0, i), s.substring(i + 1)) : parse(s, null);
}

private static VersionDelimiter parse(String s, @Nullable String classifier) {
int i1 = s.indexOf('.');
int i2 = s.indexOf('.', i1 + 1);

if (i1 == -1 || i2 == -1) {
return UNKOWN;
}

try {
String s1 = s.substring(0, i1);
String s2 = s.substring(i1 + 1, i2);
String s3 = s.substring(i2 + 1);
return new VersionDelimiter(Integer.parseInt(s1), Integer.parseInt(s2), Integer.parseInt(s3), classifier);
} catch (NumberFormatException e) {
return UNKOWN;
}
}

public boolean isSameOrNewerVersion(VersionDelimiter vd)
{

public boolean isSameOrNewerVersion(VersionDelimiter vd) {
return isSameOrNewerVersion(vd.major, vd.minor, vd.patch);
}

public boolean isSameOrNewerVersion(int major, int minor)
{

public boolean isSameOrNewerVersion(int major, int minor) {
return isSameOrNewerVersion(major, minor, 0);
}

public boolean isSameOrNewerVersion(int major, int minor, int patch)
{
if(this.major>major)
{

public boolean isSameOrNewerVersion(int major, int minor, int patch) {
if (this.major > major) {
return true;
}
else if(this.major==major)
{
if(this.minor>minor)
{
} else if (this.major == major) {
if (this.minor > minor) {
return true;
}
else if(this.minor==minor)
{
if(this.patch>=patch)
{
} else if (this.minor == minor) {
if (this.patch >= patch) {
return true;
}
}
}
return false;
}

private void wipeVersion()
{
this.major = 0;
this.minor = 0;
this.patch = 0;
}

@Override
public String toString()
{
return ""+major+"."+minor+"."+patch;
public String toString() {
if (classifier != null) {
return String.format("%d.%d.%d-%s", major, minor, patch, classifier);
}
return String.format("%d.%d.%d", major, minor, patch);
}

}

0 comments on commit 2fc97db

Please sign in to comment.