mirror of
https://github.com/ViaVersion/ViaLoader.git
synced 2024-11-15 10:45:28 +01:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
337c355866
@ -1,6 +1,6 @@
|
|||||||
<component name="CopyrightManager">
|
<component name="CopyrightManager">
|
||||||
<copyright>
|
<copyright>
|
||||||
<option name="notice" value="This file is part of ViaProtocolHack - https://github.com/RaphiMC/ViaProtocolHack Copyright (C) &#36;today.year RK_01/RaphiMC and contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." />
|
<option name="notice" value="This file is part of ViaLoader - https://github.com/RaphiMC/ViaLoader Copyright (C) &#36;today.year RK_01/RaphiMC and contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." />
|
||||||
<option name="myName" value="GPL-3.0" />
|
<option name="myName" value="GPL-3.0" />
|
||||||
</copyright>
|
</copyright>
|
||||||
</component>
|
</component>
|
@ -220,6 +220,12 @@ public enum VersionEnum {
|
|||||||
return fromProtocolVersion(ProtocolVersion.getProtocol(protocolId));
|
return fromProtocolVersion(ProtocolVersion.getProtocol(protocolId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VersionEnum fromProtocolName(final String protocolName) {
|
||||||
|
final ProtocolVersion protocolVersion = ProtocolVersion.getClosest(protocolName);
|
||||||
|
if (protocolVersion == null) return UNKNOWN;
|
||||||
|
return fromProtocolVersion(protocolVersion);
|
||||||
|
}
|
||||||
|
|
||||||
public static VersionEnum fromUserConnection(final UserConnection userConnection) {
|
public static VersionEnum fromUserConnection(final UserConnection userConnection) {
|
||||||
return fromUserConnection(userConnection, true);
|
return fromUserConnection(userConnection, true);
|
||||||
}
|
}
|
||||||
|
@ -77,15 +77,56 @@ public class VersionRange {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (this.min == null && this.max == null) return "*";
|
if (this.min == null && this.max == null) return "*";
|
||||||
else if (this.min == null) return "<= " + this.max.getName();
|
else {
|
||||||
else if (this.max == null) return ">= " + this.min.getName();
|
StringBuilder rangeString = new StringBuilder();
|
||||||
else if (Objects.equals(this.min, this.max)) return this.min.getName();
|
if (!this.ranges.isEmpty()) {
|
||||||
|
for (VersionRange range : this.ranges) rangeString.append(", ").append(range.toString());
|
||||||
final StringBuilder thisName = new StringBuilder(this.min.getName() + " - " + this.max.getName());
|
}
|
||||||
if (!this.ranges.isEmpty()) {
|
if (this.min == null) return "<= " + this.max.getName() + rangeString;
|
||||||
for (VersionRange range : this.ranges) thisName.append(", ").append(range.toString());
|
else if (this.max == null) return ">= " + this.min.getName() + rangeString;
|
||||||
|
else if (Objects.equals(this.min, this.max)) return this.min.getName();
|
||||||
|
else return this.min.getName() + " - " + this.max.getName() + rangeString;
|
||||||
}
|
}
|
||||||
return thisName.toString();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
if (this == object) return true;
|
||||||
|
if (object == null || getClass() != object.getClass()) return false;
|
||||||
|
VersionRange that = (VersionRange) object;
|
||||||
|
return min == that.min && max == that.max && Objects.equals(ranges, that.ranges);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(min, max, ranges);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VersionRange fromString(String str) {
|
||||||
|
if ("*".equals(str)) return all();
|
||||||
|
else if (str.contains(",")) {
|
||||||
|
String[] rangeParts = str.split(", ");
|
||||||
|
VersionRange versionRange = null;
|
||||||
|
|
||||||
|
for (String part : rangeParts) {
|
||||||
|
if (versionRange == null) versionRange = parseSinglePart(part);
|
||||||
|
else versionRange.add(parseSinglePart(part));
|
||||||
|
}
|
||||||
|
return versionRange;
|
||||||
|
} else {
|
||||||
|
return parseSinglePart(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static VersionRange parseSinglePart(String part) {
|
||||||
|
if (part.startsWith("<= ")) return andOlder(VersionEnum.fromProtocolName(part.substring(3)));
|
||||||
|
else if (part.startsWith(">= ")) return andNewer(VersionEnum.fromProtocolName(part.substring(3)));
|
||||||
|
else if (part.contains(" - ")) {
|
||||||
|
String[] rangeParts = part.split(" - ");
|
||||||
|
VersionEnum min = VersionEnum.fromProtocolName(rangeParts[0]);
|
||||||
|
VersionEnum max = VersionEnum.fromProtocolName(rangeParts[1]);
|
||||||
|
return of(min, max);
|
||||||
|
} else return single(VersionEnum.fromProtocolName(part));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user